|
|
|||||||
I am tinkering around with the following as I am doing some work with EventLog messages: Code: BREAK ON CLS $Starttm="05/19/2009 13:30:00" $EndTm="05/20/2009 12:11:00" ?$Starttm ?$EndTm ;get yesterdays date in utc $dtmStartDate=CreateObject("WbemScripting.SWbemDateTime") $dtmStartDate.SetVarDate '"$Starttm, CONVERT_TO_LOCAL_TIME"' $dtmEndDate=CreateObject("WbemScripting.SWbemDateTime") $dtmEndDate.SetVarDate '"$EndTm, CONVERT_TO_LOCAL_TIME"' ;Starttm = "03/20/2009 17:45:00" ;EndTm = "03/20/2009 17:55:00" ;20090320174500.000000-420 ;20090320175500.000000-420 ; -- In VBScript, it is: ;get yesterdays date in utc ;Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime") ;dtmStartDate.SetVarDate Starttm, CONVERT_TO_LOCAL_TIME ;Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime") ;dtmEndDate.SetVarDate EndTm, CONVERT_TO_LOCAL_TIME ;WScript.Echo dtmStartDate ;WScript.Echo dtmEndDate ?$dtmStartDate ?$dtmEndDate ?'Press a key...' Get $ I am sure there are a number of ways to do this.. But, it does seem the WbemScripting is the universally accepted method of doing this. Thanks, Kent |
||||||||
|
|
|||||||
OK Was able to get this working.. The only thing that I was not able to get working was: CONVERT_TO_LOCAL_TIME which I understand applies the Bias to the UTC formatted time. Code: BREAK ON CLS ; -- Was able to get some informaiton from - ;;http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=2&Number=147191 $Starttm="05/19/2009 13:30:00" $EndTm="05/20/2009 12:11:00" ?$Starttm ?$EndTm ;get yesterdays date in utc $dtmStartDate=CreateObject("WbemScripting.SWbemDateTime") $dtmStartDate.SetVarDate($Starttm) ;$dtmStartDate.SetVarDate($Starttm, CONVERT_TO_LOCAL_TIME) $dtmEndDate=CreateObject("WbemScripting.SWbemDateTime") $dtmEndDate.SetVarDate($EndTm) ;$dtmEndDate.SetVarDate($EndTm, CONVERT_TO_LOCAL_TIME) ;Starttm = "03/20/2009 17:45:00" ;EndTm = "03/20/2009 17:55:00" ;20090320174500.000000-420 ;20090320175500.000000-420 ?$dtmStartDate ?$dtmEndDate ?'Press a key...' Get $ HTH, Kent |
||||||||
|
|
|||||||
You need to get the enumeration value for the constant CONVERT_TO_LOCAL_TIME and plug it in, otherwise you are passing a string which will have undefined reaults. |
||||||||
|
|
|||||||
I think that this is what you are after: Code: BREAK ON CLS $tmStart="05/19/2009 13:30:00" $tmEnd="05/20/2009 12:11:00" "Raw start : "+$tmStart+@CRLF "Raw end : "+$tmEnd+@CRLF $DONT_CONVERT_TO_LOCAL_TIME=0 $CONVERT_TO_LOCAL_TIME=1 $oDate=CreateObject("WbemScripting.SWbemDateTime") $oDate.SetVarDate($tmStart,$CONVERT_TO_LOCAL_TIME) "Start date with CONVERT_TO_LOCAL_TIME : "+$oDate+@CRLF $oDate.SetVarDate($tmStart,$DONT_CONVERT_TO_LOCAL_TIME) "Start date with DONT_CONVERT_TO_LOCAL_TIME: "+$oDate+@CRLF $oDate.SetVarDate($tmEnd,$CONVERT_TO_LOCAL_TIME) "End date with CONVERT_TO_LOCAL_TIME : "+$oDate+@CRLF $oDate.SetVarDate($tmEnd,$DONT_CONVERT_TO_LOCAL_TIME) "End date with DONT_CONVERT_TO_LOCAL_TIME : "+$oDate+@CRLF I'm on BST (UTC+60) and this gives me: Code: Raw start : 05/19/2009 13:30:00 Raw end : 05/20/2009 12:11:00 Start date with CONVERT_TO_LOCAL_TIME : 20090519133000.000000+060 Start date with DONT_CONVERT_TO_LOCAL_TIME: 20090519133000.000000+000 End date with CONVERT_TO_LOCAL_TIME : 20090520121100.000000+060 End date with DONT_CONVERT_TO_LOCAL_TIME : 20090520121100.000000+000 |
||||||||
|
|
|||||||
Or maybe you were trying to do this: Code: BREAK ON CLS $tmStart="05/19/2009 13:30:00" $tmEnd="05/20/2009 12:11:00" $CONVERT_TO_LOCAL_TIME=Not 0 $DONT_CONVERT_TO_LOCAL_TIME=Not $CONVERT_TO_LOCAL_TIME $oDate=CreateObject("WbemScripting.SWbemDateTime") $oDate.SetVarDate($tmStart) "Raw start : "+$tmStart+@CRLF "Start date with DONT_CONVERT_TO_LOCAL_TIME: "+$oDate.GetVarDate($DONT_CONVERT_TO_LOCAL_TIME)+@CRLF "Start date with CONVERT_TO_LOCAL_TIME : "+$oDate.GetVarDate($CONVERT_TO_LOCAL_TIME)+@CRLF @CRLF $oDate.SetVarDate($tmEnd) "Raw end : "+$tmEnd+@CRLF "End date with DONT_CONVERT_TO_LOCAL_TIME : "+$oDate.GetVarDate($DONT_CONVERT_TO_LOCAL_TIME)+@CRLF "End date with CONVERT_TO_LOCAL_TIME : "+$oDate.GetVarDate($CONVERT_TO_LOCAL_TIME)+@CRLF This gives: Code: Raw start : 05/19/2009 13:30:00 Start date with DONT_CONVERT_TO_LOCAL_TIME: 19/05/2009 12:30:00 Start date with CONVERT_TO_LOCAL_TIME : 19/05/2009 13:30:00 Raw end : 05/20/2009 12:11:00 End date with DONT_CONVERT_TO_LOCAL_TIME : 20/05/2009 11:11:00 End date with CONVERT_TO_LOCAL_TIME : 20/05/2009 12:11:00 |
||||||||
|
|
|||||||
Just need to do some tweaking now... Event Logs for example, are looking for the following format: ;20090320174500.000000-420 ;20090320175500.000000-420 Thanks, Kent |