Correct the formatting
It seems like you’ve done something strange in your settings for displaying dates within Dataview. This can be handled in two ways, either through doing something like dateformat(birthday, "DDD")
where you pick the tokens for the format string from the list shown here: luxon - Immutable date wrapper. If you want to use that format in general, you can also set just once in Settings > Dataview > View Settings > Date Format. Use the same token for the format string there too.
Using the ordinal day of year
Regarding the second part of displaying birthdays later in the year, before birthdays which have already been this year, you could translate the date into the ordinal day of the year, and then introduce a choice() function to add a year to those which have already been. This can be done in multiple ways, like in the following:
```dataview
TABLE WITHOUT ID
file.link as "",
dateformat(birthday, "DDD") as Birthday
FROM "📚 Information/📝 Notes/People"
FLATTEN number(dateformat(birthday, "o")) as oday
SORT choice(oday >= number(dateformat(date(today), "o")), oday, oday+365)
```
Adapt the date format string to your liking, or set the general option as described above.
A wider more explanatory query
```dataview
TABLE WITHOUT ID
file.link as "",
birthday as Birthday
, ordinal - number(dateformat(date(today), "o")) as "Days until"
, oday
, dateformat(date(today), "o")
, ordinal
FROM "📚 Information/📝 Notes/People"
FLATTEN number(dateformat(birthday, "o")) as oday
FLATTEN choice(oday >= number(dateformat(date(today), "o")), oday, oday+365) as ordinal
SORT ordinal
```
In this script in addition to storing the ordinal day of the birthday as oday
, I also store the newly calculate ordinal value in ordinal
, and display all of the various values in the table. This also allows us to calculate how many days until the next birthday…
The key to this query is that depending on whether the day in year of the birthday is larger than the day in year of today, it either keeps the ordinal value, or adds 365 days (as in the birthday next year).
Date manipulation
In the previous query we always add 365 days to get to the next year. Another version is to actually do date manipulation to correctly account for leap year and so on, and maybe it reads a little easier too? Now the query looks like this:
```dataview
TABLE WITHOUT ID
file.link as "",
nextBirthday,
birthday as "Born",
nextBirthday.year - birthday.year as "Age"
FROM "📚 Information/📝 Notes/People"
FLATTEN date(dateformat(birthday, date(today).year + "-MM-dd")) as thisYearBirthday
FLATTEN choice(thisYearBirthday > date(today), thisYearBirthday, thisYearBirthday + dur("1 year")) as nextBirthday
SORT nextBirthday
```
And with a format setting for the date to be the ISO8601 format this results in this table:
An explanation of the query is as follows:
- In the first
FLATTEN
I create the date of this year with the day and month from the birthday, and store it in thisYearBirthday
. This is a date which might have passed already, but we tackle that in the next line
- If this years birthday has been, we add a year to the date and stores this in
nextBirthday
.
- Finally we sort on when the next birthday is
In the display section I display both the next birthday, and the original birthday, and calculate the age they will be at the next birthday. If you want you could also add nextBirthday - date(today) as "Days until"
as another column to display how far away the next birthday is…
Sorry for the lengthy answer, you could say I got a little carried away… 