Sort table by soonest birthday, dataview

I’m trying to compile a table of everyone’s birthday and sort by soonest birthday. This would display time until their birthday and put the soonest birthday first
Unfortunately in it’s current state all I’ve been able to make is increasingly more wacky ways of finding one’s age


I’ve tried quite a bit tbqh, it’s honestly simpler to post my failed code and the numerous attempts lying within, it fails because it still takes year into account when making durations

TABLE WITHOUT ID 
join(slice(split(string(date(today)-date(Birthday)),", "),1,5)), 

durationformat(date(today)-date(Birthday), "d"),

number(durationformat((date(today)-date(Birthday)), "d"))/365,

string(date(today)-date(Birthday)),

date(Birthday),

link(file.name,split(file.name," ",1)) AS Person

FROM "folder" AND #tag
WHERE Birthday
SORT date(today)-date(Birthday) DESC

The codeblock serves more as my general thought process more than anything else.

I managed to solve it using ordinals, I do think the code is a bit janky and probably could be refined more

TABLE
number(dateformat(date(Birthday),"o")) - number(dateformat(date(today),"o")) as "Days Until Birthday"

Where number(dateformat(date(Birthday),"o")) - number(dateformat(date(today),"o")) > 0

Sort number(dateformat(date(today),"o")) - number(dateformat(date(Birthday),"o")) desc

So I don’t think this method exactly appreciates leap years so better solutions welcome

Would adapting the code in the post below work for you?

i came to a similar conclusion to that independently

TABLE WITHOUT ID

"**"+dateformat(Birthday,"MMMM d")+"**" As Birthday,

"**"+
(number(dateformat(date(Birthday),"d")) - number(dateformat(date(today),"d")))
+"**"
AS Days,

link(file.name,split(file.name," ",1)) 
AS Person

WHERE
Birthday
AND
(number(dateformat(date(Birthday),"M")) - number(dateformat(date(today),"M"))) = 0

SORT number(dateformat(date(Birthday),"d")) - number(dateformat(date(today),"d")) ASC

theres 1 reason why im thinking of not using it. it only is accurate within todays month

1 Like

Update again because I’m impossible to please

I wrote a whole leap year checker for this to make it more accurate. It has to be repeated thrice and would be SO MUCH MORE ELEGANT if I could use functions

It can be theoretically improved if you first check if the ordinal of the birthday is on or before Feb 28 because right now if the date is on a leap year yet before Feb 29, its a day off

Code for the interested (I’m so sorry, it’s terrible on readability someone please fix it)

TABLE WITHOUT ID
"**"+choice(number(dateformat(date(Birthday),"y"))%4=0 and (number(dateformat(date(Birthday),"y"))%100 != 0 or number(dateformat(date(Birthday),"y"))%400 = 0),((number(dateformat(date(Birthday),"o")) - number(dateformat(date(today),"o")))-1),((number(dateformat(date(Birthday),"o")) - number(dateformat(date(today),"o")))))+"**" AS "Days Until Birthday",
"**"+dateformat(Birthday, "MMMM d")+"**" AS Birthday,
link(file.name,split(file.name," ",1)) AS Person

WHERE Birthday 
AND
choice(number(dateformat(date(Birthday),"y"))%4=0 and (number(dateformat(date(Birthday),"y"))%100 != 0 or number(dateformat(date(Birthday),"y"))%400 = 0),((number(dateformat(date(Birthday),"o")) - number(dateformat(date(today),"o")))-1),((number(dateformat(date(Birthday),"o")) - number(dateformat(date(today),"o"))))) > 0

SORT
choice(number(dateformat(date(Birthday),"y"))%4=0 and (number(dateformat(date(Birthday),"y"))%100 != 0 or number(dateformat(date(Birthday),"y"))%400 = 0),((number(dateformat(date(Birthday),"o")) - number(dateformat(date(today),"o")))-1),((number(dateformat(date(Birthday),"o")) - number(dateformat(date(today),"o"))))) 
ASC

You started out asking for the “soonest birthday”, which I assume is another way of saying the next birthday after today. You never post the format of your Birthday property, so I’m assuming YYYY-MM-DD. Given this information, what do you get if you do:

```dataview
TABLE WITHOUT ID Birthday, (Birthday - date(today)).days as "Days"
FROM "folder" and #tag
WHERE Birthday > date(today)
LIMIT 1
```

Possibly without the LIMIT 1 or expanding to list a few more of the next birthdays.


If this misses your mark completely, please give some examples of the files containing the birthday properties, so it’s easier to test our suggestions.