Please, what is the way to convert a string holding a date and write it to a Date item?
I have tried various combinations of fhSetValueAsText and fhSetValueAsDate to no avail.
I have several hundred media items imported from another program. I am trying to extract a date entry from the item’s Note field and place it in the appropriate Date.
The Date string varies from an exact date, to a year, a circa, or a between range.
I have searched the Knowledge Base and Forum but have not found an answer.
I’m looking for something to replicate the process used when manually typing into the Date on the Property box from the keyboard.
Many thanks for any input.
* Parse String to Date
Parse String to Date
Regards
MikeJ
MikeJ
- tatewise
- Megastar
- Posts: 27087
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Parse String to Date
Yes, handling Date formats is relatively complex.
The reference details are in the How to Write Plugins help pages under the The Family Historian API.
But instead of the Function Index where such as fhSetValueAsText and fhSetValueAsDate are documented, look in the Objects section where Date and Datept methods are documented.
So in your case, you need a script such as:
local dtDate = fhNewDate() create a new Date type
local bResult = dtDate:SetValueAsText(strText,true) convert Note text to a Date and allow Date Phrase
local bOK = fhSetValueAsDate(ptrDate,dtDate) save Date in OBJE.DATE field
If the Text is in a recognised FH Date format, then job done, otherwise it will save as a Date Phrase.
Then run the Fix Date Fields Plugin that converts Date Phrases holding a range of Date formats from other products into valid FH Date formats.
The reference details are in the How to Write Plugins help pages under the The Family Historian API.
But instead of the Function Index where such as fhSetValueAsText and fhSetValueAsDate are documented, look in the Objects section where Date and Datept methods are documented.
So in your case, you need a script such as:
local dtDate = fhNewDate() create a new Date type
local bResult = dtDate:SetValueAsText(strText,true) convert Note text to a Date and allow Date Phrase
local bOK = fhSetValueAsDate(ptrDate,dtDate) save Date in OBJE.DATE field
If the Text is in a recognised FH Date format, then job done, otherwise it will save as a Date Phrase.
Then run the Fix Date Fields Plugin that converts Date Phrases holding a range of Date formats from other products into valid FH Date formats.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry