Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

another n00b messing with date strings

Status
Not open for further replies.

br0ck

MIS
Apr 25, 2002
467
US
hi,

im working on a script that pulls info from NTeventlog and writes it to a file.

Code:
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("C:\EventScript.txt", ForAppending, True)
'sets the file name and location
'


strComputer = "mymailserver"
'sets to local computer e.g. "."
'
'

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


Set colLoggedEvents = objWMIService.ExecQuery _
        ("Select * from Win32_NTLogEvent Where Logfile = 'Application' and " _
            & "EventCode = '1016'")
'Sets log file and Event ID  Number
'
'
For Each objEvent in colLoggedEvents

    objTextFile.WriteLine( "Computer Name: "& objEvent.ComputerName & vbCrLf _
 & "Event ID: "& objEvent.EventCode & vbCrLf _
 & "Time Written: "& objEvent.TimeWritten & vbCrLf _
 & "Event Type: "& objEvent.Type & vbCrLf _
 & "User: "& objEvent.User & vbCrLf _
 & "Source: "& objEvent.SourceName & vbCrLf _
 & "Descripition: "& vbCrLf & objEvent.Message & vbCrLf & vbCrLf)
 objTextFile.WriteLine( "======================================================================================================================")
 
'Sets Event data to return
'
'

Next

objTextFile.Close

Const EVENT_SUCCESS = 0
Set objShell = WScript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, _
    "Log wirten to file C:\EventScript.txt"
'Writes an event to app log with File Location
'
'

Wscript.Echo "Log wirten to file C:\EventScript.csv"
'echo File Location
'



my problem is that the "Time Written: "& objEvent.TimeWritten is in the following string
Code:
20061122232937.000000-300

what can i do to format it mm/dd/yyyy hh:mm?

thank you in advance


 
Option Explicit

Dim strTest

strTest = "20061122232937.000000-300"

WScript.Echo Mid(strTest, 5, 2) & "/" & Mid(strTest, 7, 2) & "/" & Left(strTest, 4) _
& " " & Mid(strTest, 9, 2) & ":" & Mid(strTest, 11, 2) & ":" & Mid(strTest, 13, 2)


Although to be honest with you, I would probably create a seperate function for each part of the date/time stamp just to make it easier to read, more portable and more flexible.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top