* How to get the current date in a plugin?

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

How to get the current date in a plugin?

Post by JoopvB » 05 Mar 2021 21:49

What is the best way to get the current date in a plugin?

User avatar
tatewise
Megastar
Posts: 27080
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

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

Post by tatewise » 05 Mar 2021 21:53

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

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

Post by JoopvB » 05 Mar 2021 21:55

Thanks Mike, I tried this, but it seems to be a date object and I like to use it as text.

User avatar
tatewise
Megastar
Posts: 27080
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

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

Post by tatewise » 05 Mar 2021 22:01

It is possible to convert a datepoint to a date and then to text but the os.date function is probably easier.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

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

Post by JoopvB » 05 Mar 2021 22:04

Yes, that's what I was looking for. Thanks!

User avatar
tatewise
Megastar
Posts: 27080
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

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

Post by tatewise » 05 Mar 2021 22:09

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Post Reply