Page 1 of 1

How to get the current date in a plugin?

Posted: 05 Mar 2021 21:49
by JoopvB
What is the best way to get the current date in a plugin?

Re: How to get the current date in a plugin?

Posted: 05 Mar 2021 21:53
by tatewise
local dpToday = fhCallBuiltInFunction("Today") in FH datepoint format
or
local today = os.date ([format [, time]]) in various formats ~ see Lua Ref Manual os library for details.
It can return a string or a table of values for each date & time component.

Re: How to get the current date in a plugin?

Posted: 05 Mar 2021 21:55
by JoopvB
Thanks Mike, I tried this, but it seems to be a date object and I like to use it as text.

Re: How to get the current date in a plugin?

Posted: 05 Mar 2021 22:01
by tatewise
It is possible to convert a datepoint to a date and then to text but the os.date function is probably easier.

Re: How to get the current date in a plugin?

Posted: 05 Mar 2021 22:04
by JoopvB
Yes, that's what I was looking for. Thanks!

Re: How to get the current date in a plugin?

Posted: 05 Mar 2021 22:09
by tatewise
e.g.
local strToday = os.date() produces the default 05/03/2021 22:08:24
local strToday = os.date("%d %B %Y") produces 05 March 2021
See https://www.tutorialspoint.com/c_standa ... rftime.htm for format options.