WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: stanl on June 16, 2015, 07:09:23 AM

Title: Date Math Again
Post by: stanl on June 16, 2015, 07:09:23 AM
I need to convert the WB TimeYmdHms()  Into a value with say 5 decimal places to query a MySQL table with timestamps so I can look for timestamps >= my WB time. I tried this (as the TimeDiffSecs is limited to a 60 year lookback)

Code (Winbatch) Select

Decimals(5)
t1=TimeYmdHms()
t2=TimeDiffDays(t1,"1899:12:30:00:00:00")
t3=TimeDiffSecs(t1,ObjectType("DATE",t2))

Message("",t2:@CRLF:t2:".":t3)


My t3 var is about 1 hour off when I put the value into Excel and format as a datetime.

I cannot use MYSQL syntax in this script.  I know this is a kludge.
Title: Re: Date Math Again
Post by: td on June 16, 2015, 08:15:19 AM
COM Automation's date representation is a little more involved than gluing a couple of integers together.  Give the following a try:

Code (winbatch) Select
Decimals(5)
fDate = ObjectType("R8",ObjectType("DATE",TimeYmdHms()))
Title: Re: Date Math Again
Post by: stanl on June 16, 2015, 10:18:21 AM
I like that, thanks. Saves me from my huge math kludge.
Title: Re: Date Math Again
Post by: stanl on June 17, 2015, 05:29:21 AM
One more thing worth noting. I haven't worked with MySQL since 2005 and most of that code was based on the 2005 WB compiler. Truth be told 2005 is the basis for the majority of the ADO code I have written.

ObjectType() is truly (IMHO) one of the most important functions added to WB. Tony's on-liner only prompts me to dig deeper into what that function can do.
Title: Re: Date Math Again
Post by: DAG_P6 on June 19, 2015, 11:54:22 AM
More impressive, in some respects, is that your 2005 code probably worked with few changes in 2015. ;)