R. E. Cook
Home 
Contact Us 

Dr. Cook
Resume 

RunningShoes Library for WinRunner 
RunningShoes 

Custom WinRunner Functions 
and Utilities,
to Your Specs
Custom 

A Random Collection of WinRunner Solutions
Solutions 

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

R. E. Cook Consulting

 


Formatting Dates

Functions: DateFormat(), JulDateFormat(), WrDateFormat()


WinRunner provides a single date format, one that is not particularly useful ("Mon Aug 26 04:51:03 1996"). The Y2K add-in allows verifying a handful of other formats, but we are still quite limited in the formats we can produce.

How often have you struggled to generate dates in other formats? 

The DateFormat functions will generate virtually any format imaginable for any given date (expressed in standard American English).* The functions use a format string to determine how to format the output date. The three flavors of the function differ only in how the date is input. DateFormat() accepts year, month, day parameters, WrDateFormat() accepts a standard WinRunner date number, and JulDateFormat() accepts a Julian date.

The format string tells the function which date components you desire (year, month, day, weekday), and how you want each component formatted. 


Available components and formats

Date Component

Available Formats

Days, numeric

Allow 1 or 2 digits, as needed (1, 31)
Force 2 digits (01, 31)

Days, text

3-letter abbreviation (Mon, Tue)
Full name (Wednesday, Saturday)

Months, numeric

Allow 1 or 2 digits, as needed (1, 12)
Force 2 digits (01, 12)

Months, text

3-letter abbreviation (Jan, Sep)
Full name (August, November)

Years

2 digits, no century (01, 99)
4 digits, with century (2002, 1999)

 

Examples of format strings and resulting output

Desired Output Date

Format String

"Monday, August 26, 1996"

"DDDD, MMMM D, YYYY" 

"6 Aug., 96"

"D MMM., YY"

"31 December, 1999"

"D MMMM, YYYY"

"9/27/52" (USA, m/d/y)

"M/D/YY"

"27/9/52" (elsewhere, d/m/y)

"D/M/YY"

"January 1, 2000"

"MMMM D, YYYY"

"2000-01-01" (y-m-d)

"YYYY-MM-DD"

 

Examples achievable with multiple function calls 

"2nd of February, 1901"

Call Ordinal() for the day and its suffix, then DateFormat() for the month and year.

# Define the date.
day = 2;
month = 2;
year = 1901;

# Create the ordinal version of the day.
format_date = Ordinal(day) & " of ";

# Append the remainder of the date.
format_date = format_date & DateFormat("MMMM, YYYY", year, month, day);

 

"MONDAY, AUGUST 26, 1996"

First generate the mixed-case date with DateFormat, then convert it to upper case.

# Create the mixed-case version.
format_date = DateFormat("DDDD, MMMM D, YYYY", year, month, day);

# Convert to upper case.
format_date = toupper(format_date);

 

* As long as you can't imagine dates using components other than those given in the "Available components and formats" table above!


Updated 17 January 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.