Show current european date


#1

Hey everyone,

i want do show the current date in my prototype. The european date format is for example 07.02.2021 (day.month.year). If i use the [[Now.getDay()]] function, is does not show the 0 before a single digit date. Does anyone know, if it´s possible to show a 0 before a single digit current date? If the date is for example the 15th, the 0 should not show up.

Thanks for your help :slight_smile:


#2

Leveraging from an old forum thread, and StackOverflow example, one method to do this is to prepend a zero to the current date, then extract only the last two digits from the result. So, if today’s date is the 4th, the result is “04” which is only two digits. If today’s date is the 14th, the result is “014” and the last two digits of course are “14”.

Here is the expression in Axure: [["0".concat(Now.getDate()).slice(-2)]]

  • (Note that .getDate() returns the numeric day of the month, but .getDay() returns the numeric day of the week, starting with Sunday = 0, Monday = 1, etc.)

Another method, which I prefer for elegance and reliability, is to use the .toLocaleDateString() function with a european country as a parameter. It turns out this will/should show two digits per field with leading zeros by default (but there are options to force this formatting; see the StackOverflow link above for details.)

Here is the expression in Auxre, (using “french-France” as an example locale/country):
[[Now.toLocaleDateString('fr-FR')]]

  • For today’s date of July 22, 2021 this would show “22/07/2021”

  • If you want to show dots instead of slashes, you can append the .replace() function like so
    [[Now.toLocaleDateString('fr-FR').replace('/','.')]]
    …which would show “22.07.2021”


#3

Thank you so much! Worked like a charm :slight_smile: