How to get today date onClick?

A newbie question, how to get the current date values year, month, day (not just the datestamp today), just once onClick (not repeating every second, every minute, hour, …)

I read the document of package justinmimbs/date and found an excellent example of calender table but could’nt find solution.

There is a similar question in stackoverflow but there is no case working in elm 0.19.1

Alternatively, how to do it if subscriped from JavaScript?

I think what you’re looking for is all in a standard package, elm/time? You could use

Start the task when getting the click message and afterwards display the data or something like that.

1 Like

I made an Ellie showing how this might work… As @IloSophiep says, it uses the elm/time package, but rather than using I just assumed Time.utc for the timezone.


Thanks a lot for your quick response and a good example.
I’ll try next to make a module to expose a simple getDate(now) function returning (year, month, day) simply when clicked. I believe, your example in Ellie helps me a lot while doing it.
The module shall be connected to the main module calculating the sun rise / sun set times etc here, where I must input the dates always manually.

Thank you for helpful info. Having now that so as the example by @sparksp I think I know how to get the date and the current time.
I found that time can be easily extended with date.
Time.toMonth can be converted to Int and further to String using Case as in the Ellie example by @sparksp .

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