how to create a date with a year, month and day

Started by jwt, November 06, 2024, 08:20:01 AM

Previous topic - Next topic

jwt

May be I overlooked it in the manual, but can I create a date with a giving year, month and date.

I have to calculate the date using 0001/01/01 and the number of days since 0001/01/01.
Something like:
AD_Year = function("0001:01:01")
AddDays = "0000:00:%NumberOfdays%:00:00:00"
RealDate=TimeAdd(AD_Year, AddDays)


Suggestions how to do this are appreciated.

best regards, jan Willem Teunisse from the Netherlands

td

; Use the current date to get days for this example.
Now = TimeYmdHms()
Days = TimeDiffDays(Now, '0001:01:01:00:00:00')

AddDays ='0000:00:':Days:':00:00:00'
NewTime = TimeAdd('0001:01:01:00:00:00', AddDays)
Message('Now ':Now, 'Calculated ':NewTime)
exit
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

spl

Why not something as simple as [and, of course, hours/minutes/seconds could be added]

month = '12'
day = '13'
year = '2014'
vtDate = ObjectType("DATE","%month%/%day%/%year%") ;or whatever order, delineator used
Message("your date",vtDate)
Stan - formerly stanl [ex-Pundit]

td

It is more efficient to manually encode the base date if it is a constant.  However, if the base data is not a constant, using ObjectType is a good option. The function does not support a lot of date formats but it does support the conventional forwardslash format.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

jwt

Thanks for your support, January First, year 1 A.D. is a constant, so I used that example of TD