Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-03-2013, 01:07 PM
amatbrewer amatbrewer is offline
Registered User
 
Join Date: Oct 2013
Posts: 7
Timestamp including milliseconds

I need to capture the current datetime during a script including milliseconds. I have searched the posts and online and so far have found no way to do it. I know the resolution should be available since it can be included in logs.

Thanks for any help you can provide.
Reply With Quote
  #2  
Old 10-03-2013, 01:23 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,633
Hello amatbrewer,

Are you using SecureCRT?

If so, what version? (and on what platform?)

What script language are you using to write the script?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 10-18-2013, 11:30 AM
amatbrewer amatbrewer is offline
Registered User
 
Join Date: Oct 2013
Posts: 7
I am using SecureCRTv6.2.3 and writing the script in VBA.

Thanks for any info you can provide.
Reply With Quote
  #4  
Old 10-18-2013, 01:30 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,633
Hello amatbrewer,

Quote:
I need to capture the current datetime during a script including milliseconds. I have searched the posts and online and so far have found no way to do it. I know the resolution should be available since it can be included in logs.
Based on the prior statement, I assume your need for capturing milliseconds is *not* associated with SecureCRT's logging then, correct?

Sorry, I have no advice regarding VBA.

SecureCRT is capable of hosting ActiveX Script engines. Please note that VBA and VBScript are not the same thing.

VBScript and JScript are both freely available from Microsoft. You probably already have them installed.

I do not know of any VBScript built-in function that can get milliseconds (from the OS for example), but there is one in JScript.

In the scripting manual available on our website we provide some resources to Microsoft's VBScript/JScript documentation (pages 3-4).

Here is an example derived from that documentation:

Code:
# $language = "JScript"
# $interface = "1.0"

function TimeDemo(){
   var d, s = "The current local time is: ";
   var c = ":";
   d = new Date();
   s += d.getHours() + c;
   s += d.getMinutes() + c;
   s += d.getSeconds() + c;
   s += d.getMilliseconds();
   return(s);
}

strDateMS = TimeDemo();

crt.Dialog.MessageBox(strDateMS);
The above resulted in the current time displayed in the format of hh:mm:ss:ttt (where t represents milliseconds).

I am not that familiar with JScript, but those built-in functions did not seem to compensate for the missing leading 0 for single digit numbers in the getMinutes() and getSeconds() functions, so if you use those, you would probably need an if/else statement to handle that.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 10-18-2013, 02:04 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,633
Hi amatbrewer,

A colleague showed me another example that *is* possible using WMI.

If interested in that example instead, please send an email to support@vandyke.com and include "Attn Brenda - Forum Thread #11217" in the subject line.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #6  
Old 10-18-2013, 02:37 PM
amatbrewer amatbrewer is offline
Registered User
 
Join Date: Oct 2013
Posts: 7
Thanks for the reply.
"VBA and VBScript are not the same thing"
I did not realize that. I am using VBScript.
Reply With Quote
  #7  
Old 10-18-2013, 03:30 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,633
Hi amatbrewer,

Oh good, the WMI example is in VBScript:

Code:
' Use WMI to get at the current time values
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objItem In colItems
    strLocalDateTime = objItem.LocalDateTime
Next
' strLocalDateTime has the following pattern:
' 20111013093717.418000-360   (That is,  YYYYMMDDHHMMSS.MILLIS(zone))
strYear   = Left(strLocalDateTime, 4)
strMonth  = Mid(strLocalDateTime, 5, 2)
strDay    = Mid(strLocalDateTime, 7, 2)
strHour   = Mid(strLocalDateTime, 9, 2)
strMinute = Mid(strLocalDateTime, 11, 2)
strSecond = Mid(strLocalDateTime, 13, 2)
' skip the "." and start with offset char #16
strMillis = Mid(strLocalDateTime, 16, 3)  ' 6 digits, but last 3 are always zero
' Last 4 chars are the time zone
strTimeZone = Right(strLocalDateTime, 4)

MsgBox _
    "Year-Month-Day__Hour-Minute-Second.Milliseconds" & vbcrlf & vbcrlf & _
    vbtab & _
    Join(Array(strYear, strMonth, strDay), "-") & "__" & _
    Join(Array(strHour, strMinute, strSecond), "-") & "." & strMillis & _
    vbcrlf & vbcrlf & _
    "Time Zone: " & strTimeZone
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #8  
Old 10-21-2013, 10:05 AM
amatbrewer amatbrewer is offline
Registered User
 
Join Date: Oct 2013
Posts: 7
Brenda,
That is exactly what I need! Much thanks.

Dave
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:11 PM.