Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: YmdHms To SystemTime YmdHmsToSystemTimeA Convert Date Parse VT_Date ObjectType Variant VariantTimeToSystemTime
#DefineFunction udfYmdHmsToSystemTime( ymdhms ) ;-------------------------------------------------------------------------------- ; udfYmdHmsToSystemTime : Convert ymdhms To SystemTime ;-------------------------------------------------------------------------------- ; parm1 : ymdhms WIL formatted time YYYY:MM:DD:HH:MM:SS ;-------------------------------------------------------------------------------- ; returns : System time in WIl format or @FALSE on error. ;-------------------------------------------------------------------------------- ; Deana Falk ; 2014.01.28 Initial Release ;-------------------------------------------------------------------------------- ; A variant time is stored as an 8-byte real value (double), representing a date between January 1, 100 and December 31, 9999, inclusive. ; The value 2.0 represents January 1, 1900; 3.0 represents January 2, 1900, and so on. Adding 1 to the value increments the date by a day. ; The fractional part of the value represents the time of day. Therefore, 2.5 represents noon on January 1, 1900; 3.25 represents 6:00 A.M. ; on January 2, 1900, and so on. Negative numbers represent the dates prior to December 30, 1899. ; ; Using the SYSTEMTIME structure is useful because: ; It spans all time/date periods. MS-DOS date/time is limited to representing only those dates between 1/1/1980 and 12/31/2107. ; The date/time elements are all easily accessible without needing to do any bit decoding. ; The National Language Support data and time formatting functions GetDateFormat and GetTimeFormat take a SYSTEMTIME value as input. ; It is the default Win32 time and date data format supported by Windows NT and Windows 95. ; ; Convert to Variant time ErrorMode(@OFF) vtime=ObjectType("DATE",ymdhms) ErrorMode(@CANCEL) If vtime==0 Pause("Error","Invalid Date") Return 0 Endif ; Convert VariantTime To SystemTime ; The VariantTimeToSystemTime function will accept invalid dates and try to fix them when resolving to a VARIANT time. For example, ; an invalid date such as 2/29/2001 will resolve to 3/1/2001. Only days are fixed, so invalid month values result in an error being returned. ; Days are checked to be between 1 and 31. Negative days and days greater than 31 results in an error. A day less than 31 but greater than the ; maximum day in that month has the day promoted to the appropriate day of the next month. A day equal to zero resolves as the last day of the ; previous month. For example, an invalid dates such as 2/0/2001 will resolve to 1/31/2001. ;INT VariantTimeToSystemTime( ; _In_ DOUBLE vtime, ; _Out_ LPSYSTEMTIME lpSystemTime ;); oleaut32 = strcat(dirwindows(1), "oleaut32.dll") bufsize = 16 lpSystemTime = BinaryAlloc( bufsize ) ret = DllCall( oleaut32, long:"VariantTimeToSystemTime", double:vtime, lpbinary:lpSystemTime ) if ret == 0 Pause("Error","Invalid Date") Return 0 Endif ; Get SystemTime elements ;typedef struct _SYSTEMTIME { ; WORD wYear; ; WORD wMonth; ; WORD wDayOfWeek; ; WORD wDay; ; WORD wHour; ; WORD wMinute; ; WORD wSecond; ; WORD wMilliseconds; ;} SYSTEMTIME, *PSYSTEMTIME; year = BinaryPeek2(lpSystemTime,0) month = StrFixLeft(BinaryPeek2(lpSystemTime,2),"0",2) dayofweek = StrFixLeft(BinaryPeek2(lpSystemTime,4),"0",2) day = StrFixLeft(BinaryPeek2(lpSystemTime,6),"0",2) hours = StrFixLeft(BinaryPeek2(lpSystemTime,8),"0",2) minutes = StrFixLeft(BinaryPeek2(lpSystemTime,10),"0",2) seconds = StrFixLeft(BinaryPeek2(lpSystemTime,12),"0",2) millseconds = StrFixLeft(BinaryPeek2(lpSystemTime,14),"0",2) ; Convert to WIL format systemymdhms = StrCat(year,":",month,":",day,":",hours,":",minutes,":",seconds) ;Clean up BinaryFree(lpSystemTime) Return systemymdhms #EndFunction systemymdhms = udfYmdHmsToSystemTime( Timeymdhms() ) Pause('SystemTime',systemymdhms) Exit
Article ID: W17517
Filename: YmdHms To SystemTime.txt
File Created: 2014:01:28:10:00:56
Last Updated: 2014:01:28:10:00:56