Page 1 of 1 1
Topic Options
#194012 - 2009-05-26 07:25 PM UTC using WbemScripting
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#194027 - 2009-05-27 07:28 PM Re: UTC using WbemScripting [Re: Kdyer]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#194036 - 2009-05-28 10:39 AM Re: UTC using WbemScripting [Re: Kdyer]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.
Top
#194037 - 2009-05-28 11:33 AM Re: UTC using WbemScripting [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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

Top
#194038 - 2009-05-28 12:09 PM Re: UTC using WbemScripting [Re: Richard H.]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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

Top
#194043 - 2009-05-28 07:00 PM Re: UTC using WbemScripting [Re: Richard H.]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
2 registered (morganw, mole) and 414 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.154 seconds in which 0.088 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org