R. E. Cook
Contact Us 

Dr. Cook

RunningShoes Library for WinRunner 

Custom WinRunner Functions 
and Utilities,
to Your Specs

A Random Collection of WinRunner Solutions

Creating DLLs for WinRunner 
"DLLs Demystified" 
(Mercury Interactive's Worldwide Users Conference 2000)

R. E. Cook Consulting

Interpreting Date/Time Strings 

Functions: DateFromString(), DateTimeFromString(), JulFromDateString(), WrFromDateString(), WrFromDateTimeString(), TimeFromString(), TimeSecondsFromString()

How long ago was "2 January 2005, 13:27:52"?

It's simple with the date-interpretation functions in RunningShoes. It's a whole lot of trouble without RunningShoes. WrFromDateTimeString() converts that date string to the date value 1104694072, which you can work with just like any other WinRunner date value.

WinRunner provides a method to convert a date value to a formatted string, using time_str(). Going the other direction, from a string to a date value, has always been challenging at best, with no built-in support. You had to do it all yourself!

That problem is now a thing of the past – date strings can easily be converted to machine-readable dates that you can then manipulate in your WinRunner scripts. All you have to do is specify the order of the various date fields in the date string, and whether they are alpha or numeric. Specify these fields in a simple format string.

Available functions

WrFromDateString() and WrFromDateTimeString() convert dates to WinRunner date-time values, like those generated with get_time().

DateFromString() and DateTimeFromString() interpret date strings, generating individual date-time components, e.g., year, month and day.

JulFromDateString() converts dates to Julian date numbers.

TimeFromString() and TimeSecondsFromString() interpret time strings, yielding individual time components (hours, minutes, seconds).

Readable date fields and formats

Date Field Readable Formats
Years 2 digits, no century (01, 99)
4 digits, with century (2002, 1999)
Months, alpha Abbreviations, at least 3 letters (Jan, Sept., dec)
Full name (August, NOVEMBER)
Months, numeric Mixed 1 and 2 digits (1, 12)
Forced 2 digits (01, 12)
Days, alpha Abbreviations of at least 3 letters (Mon, TUES, thurs.)
Full names (Wednesday, SATURDAY)
Days, numeric Mixed 1 and 2 digits (1, 31)
Forced 2 digits (01, 31)
Hours, numeric Mixed 1 and 2 digits (1, 12, 23)
Forced 2 digits (01, 09, 13)
Hours, 12 hour Upper case, w/ or w/o periods (10 AM, 5 P.M.)
Lower case, w/ or w/o periods (9 a.m., 9pm)
Single letters (05a, 7p, 4A, 9 P)
Minutes, numeric Mixed 1 and 2 digits (1, 59)
Forced 2 digits (01, 10)
Seconds, numeric Mixed 1 and 2 digits (1, 59)
Forced 2 digits (01, 10)

Examples of input date strings and the corresponding format strings

Input Date String Format String
"Monday, August 26, 1998" "dd, mm d, y"
"6 Aug., 98" "d mm, y"
"31 December, 1999" "d mm, y"
"9/27/82" (USA, m/d/yy) "m/d/y"
"27/9/82" (elsewhere, d/m/yy) "d/m/y"
"January 1, 2000" "mm d, y"
"2000-01-01" (yyyy-mm-dd) "y-m-d"
"31/01/2005 11:15:07 AM" "d m y, h:t:s hh"
"12/31/1999 23:59" "m/d/y h:t"
"26 Aug 04 1:30 AM" "d mm y h:t hh"
"Monday, 15 January, 2005, 1:18:12 p.m." "dd, d mm, y, h:t:s hh"
"11:15:07 AM" "h:t:s hh"
"1:18:12 p.m." "h:t:s hh"
"01:01:01" "h:t:s"
"1:01:01 p" "h:t:s hh"
"23:59:59" "h:t:s"

Updated 11 November 2005

Top of  This Page | R. E. Cook Home Page

Copyright R. E. Cook Consulting, 2000 - 2011.
All rights reserved.

The site is designed to look best when viewed with Internet Explorer 5.0 - 8.0. Results with other browsers will probably deviate from what is intended.

NOTE: This website refers to registered trademarks and service marks that are owned by other companies, including Mercury Interactive, WinRunner, TestDirector, TSL, Microsoft, Windows.