Working with dates. Part 1: Getting Tomorrow's Date

When writing scripts we often deal with dates. There are certain date value formats and TestComplete routines that help handle dates.

TestComplete's scripting engine supports OLE-compatible data types, the date-time values are implemented as floating-point variant values in a special format. The integer part of this value represents the number of days that have passed since December 30, 1899. The number after the decimal separator represents the fraction of a 24-hour period that has elapsed. Below are some examples of date-time values and their meaning:

0.25December 30, 1899. 6:00 AM
36345.5July 4, 1999. 12:00 PM
39094.65625January 12, 1899. 3:45 PM

When you are only working with date values the fractional part can be omitted.

TestComplete has the Utilities object that contains methods and properties that can be useful when operating with dates.

DateSeparatorSpecifies the character separating year, month and day in date values.
LongDateFormatSpecifies the format string used to convert a date value to a string.
ShortDateFormatSpecifies the format string that is used to convert a date value to a short string.
TwoDigitYearCenturyWindowSpecifies the integer value used to convert strings to date and time values.


DateReturns the current date set on your computer.
DateTimeToFileDateConverts a variant value that stores date and time to an integer value.
DateTimeToStrConverts the variant value that stores date and time to a string.
DateTimeToStringConverts a variant value storing date and time to a string using the specified format string. (For VBScript and DelphiScript only.)
DateTimeToSystemTimeConverts a variant value that holds a date and time, to a TSystemTime value. (For VBScript and DelphiScript only.)
DateToStrConverts a variant value holding a date to a string.
DayOfWeekReturns the day of the week for the specified date.
DecodeDateSplits the specified date value into the year, month and day of the month. (For VBScript and DelphiScript only.)" 
EncodeDateConverts the date specified by year, month and day to a variant value.
FileDateToDateTimeConverts an integer value that stores the timestamp of a file to a variant value storing the date and time.
FormatDateTimeConverts the given date-time value to a string using the specified format.
IncMonthIncrements the given date value by the specified number of months.
IsLeapYearDetermines whether the given year is a leap year.
NowReturns the current date and time.
ReplaceDateChanges the date part of the first parameter into the new date that is specified as the second parameter. (For VBScript and DelphiScript only.)
StrToDateConverts the specified string to a value that encodes the date.
StrToDateTimeConverts the specified string to a value that encodes the date and time.
SystemTimeToDateTimeConverts a TSystemTime value to a variant value that encodes the date and time.

The Utilities object is accessible if the Utilities plug-in is installed (by default it is). The plug-in file (tcUtilities.pls) is supplied with TestComplete and located in the Extensions folder. The object is available for all supported scripting languages, so that you can use it to operate with date values regardless of the chosen language. The name of the Utilities object is not mandatory, so the Utilities.Now() and Now() method calls are both valid.

The samples below demonstrates how this object can be applied to calculate the tomorrow's date. The current date is obtained via the Utilities.Date() method. Then the current date value is treated as number and is incremented by 1. Another method of the Utilities object is used to convert the date value into a string that is posted to TestComplete's log.


Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading