How to get date with st nd or th using formatdate

Trying to get the day 16th 2nd etc from date field but i can’t figure out the right code…

Date formatting uses Moment.js formats.
This should help:

More: https://momentjs.com/

Thanks! I didn’t know that. Awesome

Actually doesn’t work. In wappler date is small “d” not capital D and “do” or “Do” don’t work. Neither do other moment variants…

next_birthday.formatDate(“ddd d”)

I saw i can add moment.js fraemwork to the page but then how do i use it…? confused.

Yes currently we have our own formatting. But also already have MomentJS available as framework to be used. Currently it is used in the date picker only, but I think it should be pretty easy to add an extra formatter for it as well.

Something like formatMomentDate - that will do date formatting accourding to momentJS rules.

Maybe @patrick can have a look at it.

2 Likes

So i guess i’ll do it in php but how to access the record field?

<?php echo date('dS F Y', next_birthday);?> didn't work.

Using PHP won’t work here as PHP is parsed before the page is send to client side. And all the Wappler magic happens on client side. So next_birthday does not exist as far as PHP is concerned.

Only options I see here is to either wait for a solution from Wappler… or manually put in conditions for placing st, nd or th after the date’s date part.

1 Like

Here a custom formatter that uses moment.js for formatting the date.

Place following script in a js file or script block:

dmx.Formatter('string', 'formatDate2', function(val, format) {
  return moment(val).format(format);
});

Now use it like:

{{ next_birthday.formatDate2("dddd, MMMM Do YYYY") }}
6 Likes

Team @George @patrick can we have this built in visually already?

Hi @patrick just to get update if this will be added into Wappler visual interface?

Please consider it. Will be much helpful for those who don’t hand code as requested here. Localized Format dates and times output