Hi Jay,
Below is the script I wrote. This works even if dates are illegal dates such as "bad date". It converts them into a legal date "INT (bad date)" so no potential information is lost. I did test on all possible GEDCOM date styles.
Note that this scripts uses a feature of the DateParts command I forgot to document in the help. If it is feed an invalid date, it returns an error message explaining what is wrong with the date. When there is an error, parts[0]=1 and parts[1] is the error. A valid data will always have parts[0]=5 (although some might be empty). I will add the missing documentation to next version of GEDitCOM Editor.
Finally, I wrote this using GEDitCOM II, 3.1 (beta). This version has some changes to internal scripting. This script will probably work in 3.0 version too. Or get beta version from this link:
Regards, John
! Convert to GEDCOM Dates (Internal Script for GEDitCOM II)
! Created: 2024-01-18
! Author: John Nairn
!
! Description: This script will changes dates in all (or selected)
! records to GEDCOM style dates. It is not needed for files used in
! GEDitCOM II (because it recognizes many date styles), but it might
! be useful if one finds a file with non-standard dates and might
! want to export those dates to a good GEDCOM file.
! Script name and version requirement
#scriptName="Convert to GEDCOM Dates"
! Need a document open
PreChecks #scriptName,3,1,1,1
gcapp.get gdoc,frontDocument
! Decide which records to search
#msg="Convert dates in 'All' records in the file or just the currently 'selected' records."
UserOption "#whichOnes","Which records should be changed?",#msg,"All","Cancel","Selected"
if #whichOnes="All"
gdoc.get recs,gedcomRecords
else if #whichOnes="Selected"
gdoc.get recs,selectedRecords
else
exit
endif
#numRecs = @recs.count
#numDates = 0
#fractionStepSize=0.05
#nextFraction=#fractionStepSize
gdoc.beginUndo
Repeat "#i",0,#numRecs-1
recs.#i.get rec
rec.findStructures dates,"DATE"
#numd=@dates.count
Repeat "#j",0,#numd-1
! divide this date into parts
dates.#j.get date
! Split valid dates into parts
! (an invalid date will have one part with error message)
#oldDate=@date.contents
DateParts "#parts",#oldDate
if #parts[0]>1
! prefix word
#newDate = #parts[1]
! first date (but could be empty)
if #parts[2]!=""
if #newDate!=""
#newDate&=" "
endif
#newDate&=#parts[2]
endif
! if conjuction assume as two dates
if #parts[3]!=""
#newDate&=" "&#parts[3]&" "&#parts[4]
endif
! Date coimment
if #parts[5]!=""
#newDate&=" "&#parts[5]&""
endif
else
! Convert bad dates to a valid date comment
#newDate="INT ("&#oldDate&")"
endif
! only convert dates that have changed
if #newDate!=#oldDate
date.set contents,#newDate
#numDates+=1
endif
EndRepeat
! time for progress
#fractionDone = #i/#numRecs
if #fractionDone>#nextFraction
NotifyProgress #fractionDone
#nextFraction+=#fractionStepSize
endif
EndRepeat
gdoc.endUndo "Date Conversions"
NotifyProgress 1
! output summary of the results
if #numDates==0
#msg = "No dates needed conversion to the GEDCOM date style"
else
if #numDates==1
#msg = "One date was converted to GEDCOM style date"
else
#msg = #numDates&" dates were converted to GEDCOM style dates"
endif
endif
UserOption "#done",#msg,"","OK"