Formatting date data

I would like to a Prompt for User Input and I would like to cover the variable (vdate) to a date format. On running the macro below which automatically is set to default to today's date produces the following number 1665144000. I would like to convert back to a proper date.

Keyboard Maestro Actions.kmactions (1.9 KB)
Keyboard Maestro Export

The input variable is set to Date:

and when the macro is run shows this date picker:

and the result is (1665144000):

I would like to know how to convert back to a proper date (eg 7 October 2022).

Any help would be gratefully received.

This is what the ICUDateTimeFor token is for. You can use it with your vdate variable like this to format it into a friendlier date:

%ICUDateTimeFor%vdate%d MMMM yyyy%

1 Like

gglick,

Thank you very much for the information - problem solved.

1 Like

Perhaps worth knowing, since you'll probably come up against similar again and again...

NOW() returns the current time in Unix time -- the number of seconds since the start of the "epoch". For OS X that's the seconds since 1970-01-01 00:00:00.

Because you've set your dialog's field type to "Date", KM does it's best to display your default value in date format -- it's still a number "behind the scenes". You can see this -- and confirm the above -- by putting in 0 as your default.

Using a default of 0 and the field type to "Date and Time" will also show you a thing to watch out for -- the displayed date and time will appear to be out by a number of hours. That's because NOW() is GMT while KM uses local time.

Date and time operations -- something that seem so easy to us -- can be a minefield for computers. Chapters, indeed whole books, have been written about it. KM generally hides the messiness from you, but when you want to dig into the weeds the ICU Date/Time Tokens page is a good place to start.

1 Like