Bluepoint Design

Practical Cost-Effective Solutions
Text to Serial Time VBS

Home
Up
I wrote an enormously complex macro to mathematically convert a date string to a time variable in MEP Script once but now I have found a simpler way using VBScript and the External Script command. Here's an example of the code to put into External Script:

wscript.echo(CDbl(CDate("%Date String%")))

Yep, that's all there is to the script, one line. This will return a string variable to the variable you specify in the "Save console output to:". Now convert the string to decimal with Variable Modify String and finally convert that to time using Convert Decimal to Date/Time. The command uses the double data type so it also supports time accurately. EG "8/19/1968 12:15 PM" returns "25069.5104166667".

If you would like to get real tricky you could use the IsDate function to handle strings that are not dates. In the example below it will return the string "Bad" which you can test for back in MEP.

if isdate("%Date String%") Then
wscript.echo(CDbl(CDate("%Date String%")))
else
wscript.echo("Bad")
end if

Notes:

  1. The actual time string format can very greatly. I've experimented with padded zeros, 2 and 4 digit years, military time, AM/PM, hh:mm:ss.dec, named months, abbreviated named months, and many more. It apparently accepts all common formats. This is nice because you do not have to parse the bits out to ensure they're in a specific format.
  2. It is a little slow. Takes a couple of seconds in most cases so it's not ideal if you have a lot of dates to convert. However you could make a variation of this script and pass all of them at once in an array. The reason it is slow is because MEP creates and executes a VBS file meaning it will create and destroy this file as many times as you use it.
  3. Apparently MEP executes the script with CScript so there is no worries about what your default scripting host is. IE no pop up message boxes.
 
Practical Cost-Effective Solutions