Format/translate day of the week

Hi, I want to show 2 dates inside a repeater. The problem is I need the abbreviation of the day of the week in german.

For example: Sunday 12.5.2019 should be changed to : So. 12.5.2019

I have to replace every day of the week:
Monday = Mo.
Tuesdays = Di.
Wednesday = Mi.

Can you give me a hint for a good approach, please? Do I have to use replace() ? Not sure how to do it with so many values to search for.

Replace would work great. You can chain functions together, so here we’ll be chaining 7 replace functions:

[[Now.getDayOfWeek().replace('Monday','Mo').replace('Tuesday','Di').replace('Wednesday','Mi').replace('Thursday','Do').replace('Friday','Fr').replace('Saturday','Sa').replace('Sunday','So')]]. [[Now.getDate()]].[[Now.getMonth()]].[[Now.getFullYear()]]

This will give you So. 19.5.2019 for today’s date. (I don’t know much about German dates: I’m assuming the day-of-month precedes the month.)

How it works:

Say it’s Sunday. getDayOfWeek() will return ‘Sunday’ which will be passed through the first replace() that tries to find ‘Monday’ within ‘Sunday’ and replace it with with ‘Mo’. The result of this replace() will still be ‘Sunday’ since the replace() found nothing to replace. Then the ‘Sunday’ result of the first replace() is passed through the next replace(), which tries to find ‘Tuesday’ in the ‘Sunday’ string and replace it with ‘Di’. This replace() returns the string ‘Sunday’ since it found no ‘Tuesday’, so the ‘Sunday’ result of the Tuesday replace() gets passed to the replace() seeking ‘Wednesday’, and so on down the line until the last replace() actually finds ‘Sunday’, and replaces it with ‘So’.

If today is Monday, the first replace() would succeed, passing ‘Mo’ through all of the subsequent replace() functions, which all will return ‘Mo’ since ‘Mo’ doesn’t contain ‘Tuesday’ or ‘Wednesday’ or Thursday or …


Ok I guess I have to learn more about Javascript etc. I don’t think the Axure Docs offers such fundamental stuff.

This will give you So. 19.5.2019 for today’s date. (I don’t know much about German dates: I’m assuming the day-of-month precedes the month.)

Yes, that’s right.

I added some more code from another example you have posted here to get dynamic dates:

    [[Now.getDayOfWeek().replace('Monday','Mo').replace('Tuesday','Di').replace('Wednesday','Mi').replace('Thursday','Do').replace('Friday','Fr').replace('Saturday','Sa').replace('Sunday','So')]]. [[Now.addDays(Item.dateOffset).getDate()]].[[Now.addDays(Item.dateOffset).getMonth()]].[[Now.addDays(Item.dateOffset).getFullYear()]]

I would have never guessed this works.

Thank you very much that you took the time to explain the entire procedure.

I wish they would add something like reddit gold here…

You can find a list of variables and functions Axure exposes here: V7 Variables List. You can also see all options by clicking Insert Variable of Function here:

It’s listed for v7 but it should still be almost all relevant to even v9.

Since for the most part these functions work just as you would expect in JavaScript (there are some exceptions), you can look them up online if you have any questions about what they do or how exactly they work. MDN is a great resource for this. For example. if you’re wondering what the difference between substr() and substring() is…

Note that not every function Axure provides is necessarily a standard JavaScript function, in case you can’t find it online.

1 Like

Yeah, I know about this “function+variable builder” …and I have probably seen almost every entry in the axure doc, but stuff that josephxbrick mentioned isnt written there e.g. chaining so many functions in a row. I will take a look at other resources like MDN. Thank you for the hint.

Per this nice MDN article on toLocaleDateString(), this javascript should work, but Axure loses the alpha date for some reason:

[[Now.toLocaleDateString('de-DE', "weekday: 'short', year: 'numeric', month: 'numeric', day: 'numeric'")]]
Output: 21.5.2019
…but should be Di 21.5.2019

So, you could shorten @josephxbrick’s formula a bit to
[[Now.getDayOfWeek().replace('Monday','Mo').replace('Tuesday','Di').replace('Wednesday','Mi').replace('Thursday','Do').replace('Friday','Fr').replace('Saturday','Sa').replace('Sunday','So')]]. [[Now.toLocaleDateString('de-DE', "year: 'numeric', month: 'numeric', day: 'numeric'")]]

…but what you have probably works well with your date-offset data.

1 Like

Thx I have learned a lot. I will try your changes as well.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.