Date format for dd/MM/yyyy?

Hi

Is there an in-built function that returns the date in the format of “dd/MM/yyyy”? I can see just about every other variation and most assume 2-digit year, which is a bit 1990s :slight_smile:

the closest I could find was:

formattedTime(the timeFormat's shortdate, now)

alternatively if there is a setting like

set clockformat to "24"

that will force the year interpretation to 4-digit year?

thanks

If you want to use this for any date, here is the format:

set myDate to today
log formattedTime("%m",myDate) &"/"& formattedTime("%d",myDate) &"/"& formattedTime("%Y",myDate)

If you want to use it for the current date, you can simplify it to this:
log formattedTime("%m",Date) &"/"& formattedTime("%d",Date) &"/"& formattedTime("%Y",Date)

1 Like

Hi Dave

Thanks for the reply. Before i saw your reply i had a rare moment of clarity and used the following to generate “tmorrows” date, in UK date format:

formattedTime("%d/%m/%Y", now + one day)

Would you foresee any issues with this compressed approach?

thanks

1 Like

Not at all. I think that the code I included must have come from a time before when the compressed version was not available.

Speaking of outdated formats like 2-digit years, the formatting codes using “%” are very old-school now! Take a look at the documentation on date and time formats and use the bracket formats instead:
put formattedTime("[day]/[month]/[year]", tomorrow)

or, for 2-digit day and month:
put formattedTime("[da]/[mo]/[year]", tomorrow)

And (this may not be well documented – I’ll try to correct that soon) you can also do it this way:
put tomorrow with format "[day]/[month]/[year]"

1 Like