Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • Last Modified:

VB script to compare net time

I am working on a script to compare the output of net time for several servers. The issue I am having is gathering just the information I need from the output string For example the output of server peach is

Current time at \\peach is 2/22/2011 9:55:32 AM

The command completed successfully.

Now I need to comapre just the time portion of this output. How do I isolate it?
0
Frog_1337
Asked:
Frog_1337
  • 3
1 Solution
 
prashanthdCommented:
Can you give more details on the requirement as to how you will compare etc?
0
 
prashanthdCommented:
Can you give more details on the requirement as to how you will compare etc?
0
 
prashanthdCommented:
Can you give more details on the requirement as to how you will compare etc?
0
 
RobSampsonCommented:
From the output, just take it from " is ":
strOutput = "Current time at \\peach is 2/22/2011 9:55:32 AM"
dteTime = CDate(Mid(strOutput, InStr(strOutput, " is ") + 4))

Regards,

Rob.
0
 
sam0x01Commented:
This will run net time and extract the date and time and convert it to the Date and output both strDate and dteDate.

I have noticed that the net time command responds with the US date format no matter what the regional settings are which could be an issue for countries that use different regional settings.

ie when run on 6/12/2011will likely record the date as 12/6/2011.


Set objWShell = CreateObject("WScript.Shell") 
Set objCmd = objWShell.Exec("net time \\127.0.0.1") 
strResult = objCmd.StdOut.Readall() 
set objCmd = nothing: Set objWShell = nothing 

numStartDateTime = Instr(1, strResult,"is", vbTextCompare)+2
numEndDateTime = Instr(1, strResult, "The", vbTextCompare)-5
strDateTime= Left (strResult, numEndDateTime)
strDateTime= Right(strDateTime, Len(strDateTime)-numStartDateTime)
dteTime=CDate(strDateTime)
WScript.Echo """" & strDateTime & """ """ & dteTime & """"

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now