WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: jwt on November 06, 2024, 08:20:01 AM

Title: how to create a date with a year, month and day
Post by: jwt on November 06, 2024, 08:20:01 AM
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
Title: Re: how to create a date with a year, month and day
Post by: td on November 06, 2024, 10:30:20 AM
; 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
Title: Re: how to create a date with a year, month and day
Post by: spl on November 06, 2024, 12:18:08 PM
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)
Title: Re: how to create a date with a year, month and day
Post by: td on November 06, 2024, 01:32:40 PM
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.
Title: Re: how to create a date with a year, month and day
Post by: jwt on November 07, 2024, 06:27:39 AM
Thanks for your support, January First, year 1 A.D. is a constant, so I used that example of TD