4. Chapter 14 Scripting Quicktest Professional Page 4
Dani Vainstein DotNetFactory Page 4 of 151
TimeSpan.FromSeconds ( Double ) Method............................................................... 122
TimeSpan.FromTicks ( Long ) Method ...................................................................... 123
TimeSpan.GetHashCode ( ) Method........................................................................... 124
TimeSpan.Negate ( ) Method...................................................................................... 125
TimeSpan.op_Addition ( TimeSpan, TimeSpan ) Method ......................................... 126
TimeSpan.op_Equality ( TimeSpan, TimeSpan ) Method.......................................... 128
TimeSpan.op_GreaterThan ( TimeSpan, TimeSpan ) Method ................................... 130
TimeSpan.op_GreaterThanOrEqual ( TimeSpan, TimeSpan ) Method...................... 130
TimeSpan.op_Inequality ( TimeSpan, TimeSpan ) Method ....................................... 130
TimeSpan.op_LessThan ( TimeSpan, TimeSpan ) Method........................................ 131
TimeSpan.op_LessThanOrEqual ( TimeSpan, TimeSpan ) Method .......................... 131
TimeSpan.op_Subtraction ( TimeSpan, TimeSpan ) Method..................................... 132
TimeSpan.op_UnaryNegation ( ) Method................................................................... 132
TimeSpan.op_UnaryPlus ( ) Method .......................................................................... 133
TimeSpan.Parse ( String ) Method.............................................................................. 133
TimeSpan.Subtract ( TimeSpan ) Method................................................................... 135
TimeSpan.ToString ( String ) Method ........................................................................ 136
TimeSpan.TryParse ( String, TimeSpan ) Method...................................................... 136
DOTNETFACTORY TASKS ...................................................................................................... 137
WORLD CALENDARS ......................................................................................................... 137
SYSTEM.COLLECTIONS.ARRAYLIST ................................................................................. 140
CALLCHAIN USING SYSTEM.COLLECTIONS.STACK .......................................................... 141
APPENDIX 14.A – ENUMERATIONS ........................................................................................ 144
System.DateTimeKind Enumeration .......................................................................... 145
System.DayOfWeek Enumeration .............................................................................. 145
Standard DateTime Format Strings............................................................................. 145
Custom DateTime Format Strings .............................................................................. 146
System.Globalization.DateTimeStyles Enumeration.................................................. 150
DotNetFactory
The DotNetFactory Object
Enables you to create an instance of a .NET object, and access its methods and
properties.
You can use this object to access the static methods and properties of a class that
does not have an instance constructor, for example, System.Environment, as well as
a class that does.
CreateInstance Method
Returns a COM interface for a .NET object
5. Chapter 14 Scripting Quicktest Professional Page 5
Dani Vainstein DotNetFactory Page 5 of 151
If you want to use a .NET object as an argument for a method in QuickTest, you
must first create a COM interface for the .NET object using the CreateInstance
method. Then you pass that interface as the method argument.
Set var_CreateInstance =
DotNetFactory.CreateInstance (TypeName [,Assembly] [,args])
Parameter Description
TypeName
The full name of the object type, for example,
System.Windows.Forms.Form.
Assembly
Optional. If the assembly is preloaded in the registry, you do not need to
enter it. Otherwise, you should enter the full path name, for example,
System.Windows.Forms. If you want to create an instance of a type in the
GAC (Global Assembly Cache), you can enter the short name, for example,
Forms.
Note: If you do not pass this argument, QuickTest assumes that the
assembly is resident in memory. If QuickTest does not find the assembly,
an error message is displayed during the run session.
args
Optional. The required arguments, if any, for the specified TypeName
and/or Assembly
A Variant value. Returns the defined instance of the .NET object.
QTP DotNetFactory
When QTP version 9.0 was released. I have noticed that a new utility object was added,the
DotNetFactory object.
Since, that period of time, I was working on a web application, I thought myself , that
DotNetFactory is a utility to work with .NET applications, like the DOT.NET Extensibility
In QTP Version 9.2, I so the following example in the QTP help
Set var_CreateInstance = _
DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
var_CreateInstance.Show
wait 2
var_CreateInstance.Close
And also
Set var_CreateInstance = DotNetFactory.CreateInstance("System.Environment")
msgbox var_CreateInstance.CurrentDirectory
The first example display an empty windows form. I started to think, why I need to display
a form , during a test run. The second example catch my eye, and when I tried it in qtp, I
got the following result :
6. Chapter 14 Scripting Quicktest Professional Page 6
Dani Vainstein DotNetFactory Page 6 of 151
"wow!!" I said to my self, nice to know that I can have every single environment value of
the system, especially SystemDirectory property. The others values, can be retrieved using
standard VBScript objects and QTP Environment object. So, again … I did not paid attention
and full research for the dot.net factory.
One month later, I add an issue when testing a financial application.
The application ( web based ) shows the interests to pay for each month. Because the
application is a bank system application, I can't show screenshots. But a web table was
displayed in the following format :
Date Amount
Tue, 12 Sep 2006 2500$
Thu, 12 Oct 2006 2490$
Sun, 12 Nov 2006 2475$
Tue, 12 Dec 2006 2466$
7. Chapter 14 Scripting Quicktest Professional Page 7
Dani Vainstein DotNetFactory Page 7 of 151
Fri, 12 Jan 2007 2390$
Mon, 12 Feb 2007 2285$
My problem here, were the dates. VBScript doesn't able to convert formats, to the specific
format I needed, and beside this, any user can change the display format to : mm/dd/yyyy
or mmddyy or ddmmyy etc.
dteDate = Cdate( "Tue, 12 Sep 2006" )
Because the CDate conversion error, in pure vbscript I need a function like the
follows
Option Explicit
Dim arr1, arr2, MyDate, nMonth, dteDate
MyDate = Browser("B").Page("P").WebTable("rates").GetCellData(1,1)
arr1 = Split( MyDate, "," )
arr2 = Split( arr1(1), " " )
Select Case arr2(2)
Case "Jan" : nMonth = 1
Case "Feb" : nMonth = 2
Case "Mar" : nMonth = 3
Case "Apr" : nMonth = 4
Case "May" : nMonth = 5
Case "Jun" : nMonth = 6
Case "Jul" : nMonth = 7
Case "Aug" : nMonth = 8
Case "Sep" : nMonth = 9
Case "Oct" : nMonth = 10
Case "Nov" : nMonth = 11
Case "Dec" : nMonth = 12
End Select
dteDate = DateSerial(arr2(3), nMonth, arr2(1))
msgbox dteDate
This process only to retrieve the first date, than, I have to use the DateAdd function, and
another function to convert the new date, to the desired format.
As you can see, this is a lot of work, beside, that the user can change the formats.
8. Chapter 14 Scripting Quicktest Professional Page 8
Dani Vainstein DotNetFactory Page 8 of 151
The application has hundreds of date fields, and dates fields are very critical for the
application.
From this moment I start to make a research, to find a simplest and elegant solution.
I found the System.DateTime object in the MSDN DOT.NET help, and remember
immediately of the QTP example about the System.Environment object
So I tried the follow :
Option Explicit
Dim DateTime
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
A little more research, using the MSDN help I got the ultimate date handling functionality
Option Explicit
Dim DateTime, SystemDateTime, i, Str
Set SystemDateTime = DotNetFactory.CreateInstance( "System.DateTime" )
Set DateTime = SystemDateTime.Parse( "Tue, 12 Sep 2006" )
For i = 1 To 12
9. Chapter 14 Scripting Quicktest Professional Page 9
Dani Vainstein DotNetFactory Page 9 of 151
Str = Str & DateTime.AddMonths(i).ToString( "ddd, dd MMM yyyy" ) & vbNewLine
Next
Msgbox Str
Set SystemDateTime = Nothing : Set DateTime = Nothing
So, the conclusion of all my research, is that you can use almost any DOT.NET object
supported by your Dot.Net Framework ( today is version 3 ) , so this chapter of
DotNetFactory will demonstrate only the System.DateTime and System.TimeSpan
classes. In some examples I use The System.Text.TextBuilder class,
System.Globalization.CultureInfo class, System.DateTimeKind Enumerator,
System.Globalization.Calendar and more
System.DateTime Structure
Represents an instant in time, typically expressed as a date and time of day.
The DateTime value type represents dates and times with values ranging from 12:00:00
midnight, January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December
31, 9999 A.D. (C.E.)
Time values are measured in 100-nanosecond units called ticks, and a particular date is the
number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the
GregorianCalendar calendar. For example, a ticks value of 31241376000000000L
represents the date, Friday, January 01, 0100 12:00:00 midnight. A DateTime value is
always expressed in the context of an explicit or default calendar.
More information can be found in the following link :
http://msdn2.microsoft.com/en-us/library/system.datetime.aspx
System.DateTime Fields
Name Description
MaxValue Represents the largest possible value of DateTime. This field is read-only.
MinValue Represents the smallest possible value of DateTime. This field is read-only
10. Chapter 14 Scripting Quicktest Professional Page 10
Dani Vainstein DotNetFactory Page 10 of 151
DateTime.MaxValue Field
Represents the largest possible value of DateTime. This field is read-only
The value of this constant is equivalent to 00:00:00.0000000, January 1, 0001.
DateTime.MinValue Field
Represents the smallest possible value of DateTime. This field is read-only
The value of this constant is equivalent to 23:59:59.9999999, December 31, 9999,
exactly one 100-nanosecond tick before 00:00:00, January 1, 10000.
System.DateTime Contructors
Initializes a new instance of the DateTime structure.
Name Description
DateTime (Int64)
Initializes a new instance of the DateTime structure
to a specified number of ticks.
DateTime (Int64, DateTimeKind)
Initializes a new instance of the DateTime structure
to a specified number of ticks and to Coordinated
Universal Time (UTC) or local time.
DateTime (Int32, Int32, Int32)
Initializes a new instance of the DateTime structure
to the specified year, month, and day.
DateTime (Int32, Int32, Int32,
Calendar)
Initializes a new instance of the DateTime structure
to the specified year, month, and day for the
specified calendar.
DateTime (Int32, Int32, Int32,
Int32, Int32, Int32)
Initializes a new instance of the DateTime structure
to the specified year, month, day, hour, minute, and
second.
DateTime (Int32, Int32, Int32,
Int32, Int32, Int32, Calendar)
Initializes a new instance of the DateTime structure
to the specified year, month, day, hour, minute, and
second for the specified calendar.
DateTime (Int32, Int32, Int32,
Int32, Int32, Int32, DateTimeKind)
Initializes a new instance of the DateTime structure
to the specified year, month, day, hour, minute,
second, and Coordinated Universal Time (UTC) or
local time.
DateTime (Int32, Int32, Int32,
Int32, Int32, Int32, Int32)
Initializes a new instance of the DateTime structure
to the specified year, month, day, hour, minute,
second, and millisecond.
DateTime (Int32, Int32, Int32,
Int32, Int32, Int32, Int32,
Calendar)
Initializes a new instance of the DateTime structure
to the specified year, month, day, hour, minute,
second, and millisecond for the specified calendar.
DateTime (Int32, Int32, Int32, Initializes a new instance of the DateTime structure
11. Chapter 14 Scripting Quicktest Professional Page 11
Dani Vainstein DotNetFactory Page 11 of 151
Int32, Int32, Int32, Int32,
DateTimeKind)
to the specified year, month, day, hour, minute,
second, millisecond, and Coordinated Universal Time
(UTC) or local time.
DateTime (Int32, Int32, Int32,
Int32, Int32, Int32, Int32,
Calendar, DateTimeKind)
Initializes a new instance of the DateTime structure
to the specified year, month, day, hour, minute,
second, millisecond, and Coordinated Universal Time
(UTC) or local time for the specified calendar.
DateTime.DateTime( int64 ) Constructor
Initializes a new instance of the DateTime structure to a specified number of ticks.
Set object = DotNetFactory.CreateInstance( "System.DateTime", , ticks )
Parameter Description
ticks A date and time expressed in 100-nanosecond units.
System.DateTime object
The Kind property is initialized to Unspecified.
ArgumentOutOfRangeException - ticks is less than MinValue or greater than
MaxValue.
The following code example demonstrates one of the DateTime constructors
Option Explicit
Dim SDT, dtMax, dtMin, dtCustom
Dim format
Dim SB, CI, ticks
format = "{0}) The {1} date and time is {2:MM/dd/yyyy hh:mm:ss tt}{3}"
Set SDT = DotNetFactory.CreateInstance( "System.DateTime" )
' ** Create a DateTime for the maximum date and time using ticks
Set dtMax = DotNetFactory.CreateInstance( "System.DateTime", , SDT.MaxValue.Ticks )
' ** Create a DateTime for the minimum date and time using ticks.
Set dtMin = DotNetFactory.CreateInstance( "System.DateTime", , SDT.MinValue.Ticks )
' ** Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a calendar based on
' the "en-US" culture, and ticks.
Set CI = DotNetFactory.CreateInstance( _
"System.Globalization.CultureInfo", _
"System", "en-US", False _
)
Set ticks = DotNetFactory.CreateInstance( _
"System.DateTime", ,1979, 7, 28, 22, 35, 5, CI.Calendar _
12. Chapter 14 Scripting Quicktest Professional Page 12
Dani Vainstein DotNetFactory Page 12 of 151
).Ticks
Set dtCustom = DotNetFactory.CreateInstance( "System.DateTime", , ticks )
' ** Reporting
Set SB = DotNetFactory.CreateInstance( "System.Text.StringBuilder" )
SB.AppendFormat format, 1, "maximum", dtMax, vbNewLine
SB.AppendFormat format, 2, "minimum", dtMin, vbNewLine
SB.AppendFormat format, 3, "custom", dtCustom, vbNewLine
SB.AppendFormat "The custom datetime is created from {0:N0} ticks.", ticks
Msgbox SB.ToString(), vbOkOnly, "DateTime( ticks )"
' ** Cleaning
Set SB = Nothing : Set CI = Nothing
Set dtCustom = Nothing : Set ticks = Nothing
Set dtMin = Nothing : Set dtMax = Nothing : Set SDT = Nothing
DateTime.DateTime ( int64, DateTimeKind ) Constructor
Initializes a new instance of the DateTime structure to a specified number of ticks and
to Coordinated Universal Time (UTC) or local time.
Set object =
DotNetFactory.CreateInstance( "System.DateTime", , ticks, kind )
Parameter Description
ticks A date and time expressed in 100-nanosecond units.
kind
One of the DateTimeKind values that indicates whether ticks specifies a
local time, Coordinated Universal Time (UTC), or neither.
System.DateTime object
ArgumentOutOfRangeException - ticks is less than MinValue or greater than
MaxValue.
ArgumentException - Kind is not one of the DateTimeKind values.
The following code example uses the SpecifyKind method to demonstrate how the Kind
property influences the ToLocalTime and ToUniversalTime conversion methods.
13. Chapter 14 Scripting Quicktest Professional Page 13
Dani Vainstein DotNetFactory Page 13 of 151
Option Explicit
Const DATE_PATTERN = "M/d/yyyy hh:mm:ss tt"
Dim DateTime, saveNow, saveUtcNow, myDt
Dim DateTimeKind
Private Sub DisplayNow( ByVal title, ByRef inputDt )
Dim dtString
dtString = inputDt.ToString( DATE_PATTERN )
Print title & " " & dtString & ", Kind = " & inputDt.Kind
End Sub
Public Sub Display( ByVal title, ByRef inputDt )
Dim dispDt, dtString
Set dispDt = inputDt
' ** Display the original DateTime.
dtString = dispDt.ToString( DATE_PATTERN )
Print title & " " & dtString & ", Kind = " & dispDt.Kind
' ** Convert inputDt to local time and display the result.
' ** If inputDt.Kind is DateTimeKind.Utc, the conversion is performed.
' ** If inputDt.Kind is DateTimeKind.Local, the conversion is not performed.
' ** If inputDt.Kind is DateTimeKind.Unspecified, the conversion is
' ** performed as if inputDt was universal time.
Set dispDt = inputDt.ToLocalTime()
dtString = dispDt.ToString( DATE_PATTERN )
Print "ToLocalTime: " & dtString & ", Kind = " & dispDt.Kind
' ** Convert inputDt to universal time and display the result.
' ** If inputDt.Kind is DateTimeKind.Utc, the conversion is not performed.
' ** If inputDt.Kind is DateTimeKind.Local, the conversion is performed.
' ** If inputDt.Kind is DateTimeKind.Unspecified, the conversion is
' ** performed as if inputDt was local time.
Set dispDt = inputDt.ToUniversalTime()
dtString = dispDt.ToString( DATE_PATTERN )
Print "ToUniversalTime: " & dtString & ", Kind = " & dispDt.Kind & vbNewLine
End Sub 'Display
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
' ** Get the date and time for the current moment, adjusted to the local time zone.
Set saveNow = DateTime.Now
' ** Get the date and time for the current moment expressed as coordinated universal
' time (UTC).
Set saveUtcNow = DateTime.UtcNow
' ** Display the value and Kind property of the current moment expressed as UTC and
' local time.
Call DisplayNow( "UtcNow: ..........", saveUtcNow )
Call DisplayNow( "Now: .............", saveNow )
' ** Change the Kind property of the current moment to DateTimeKind.Utc and display
' the result.
Set DateTimeKind = DotNetFactory.CreateInstance( "System.DateTimeKind" )
14. Chapter 14 Scripting Quicktest Professional Page 14
Dani Vainstein DotNetFactory Page 14 of 151
Set myDt = DateTime.SpecifyKind( saveNow, DateTimeKind.Utc )
Call Display( "Utc: .............", myDt )
' ** Change the Kind property of the current moment to DateTimeKind.Local and ' '
' display the result.
Set myDt = DateTime.SpecifyKind( saveNow, DateTimeKind.Local )
Call Display( "Local: ...........", myDt )
' ** Change the Kind property of the current moment to DateTimeKind.Unspecified and
' display the result.
Set myDt = DateTime.SpecifyKind( saveNow, DateTimeKind.Unspecified )
Call Display( "Unspecified: .....", myDt )
Set myDt = Nothing : Set DateTimeKind = Nothing : Set DateTime = Nothing
Set saveNow = Nothing : Set saveUtcNow = Nothing
DateTime.DateTime(Int32, Int32, Int32) Constructor
Initializes a new instance of the DateTime structure to the specified year, month, and
day.
Set object =
DotNetFactory.CreateInstance( "System.DateTime", , year, month, day )
Parameter Description
year The year (1 through 9999).
month The month (1 through 12).
day The day (1 through the number of days in month).
System.DateTime object
15. Chapter 14 Scripting Quicktest Professional Page 15
Dani Vainstein DotNetFactory Page 15 of 151
ArgumentOutOfRangeException .
year is less than 1 or greater than 9999
month is less than 1 or greater than 12.
day is less than 1 or greater than the number of days in month.
ArgumentException - The specified parameters evaluate to less than MinValue or
more than MaxValue.
The following code example uses the SpecifyKind method to demonstrate how the Kind
property influences the ToLocalTime and ToUniversalTime conversion methods.
Option Explicit
Dim DateTime
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime", ,1979, 7, 28)
MsgBox DateTime.ToString()
Set DateTime = Nothing
DateTime.DateTime(Int32, Int32, Int32, Calendar)
Constructor
Initializes a new instance of the DateTime structure to the specified year, month, and
day for the specified calendar.
Set object = DotNetFactory.CreateInstance(
"System.DateTime", , year, month, day, calendar )
Parameter Description
year The year (1 through 9999).
month The month (1 through 12).
Day The day (1 through the number of days in month).
calendar The Calendar that applies to this DateTime.
System.DateTime object
ArgumentNullException - calendar is a null reference (Nothing in Visual Basic).
16. Chapter 14 Scripting Quicktest Professional Page 16
Dani Vainstein DotNetFactory Page 16 of 151
ArgumentOutOfRangeException .
year is less than 1 or greater than 9999
month is less than 1 or greater than 12.
day is less than 1 or greater than the number of days in month.
ArgumentException - The specified parameters evaluate to less than MinValue or
more than MaxValue.
The time of day for the resulting DateTime is midnight (00:00:00). The Kind
property is initialized to Unspecified
The allowable values for year, month, and day depend on calendar. An exception is
thrown if the specified date and time cannot be expressed using calendar.
The System.Globalization namespace provides several calendars including
GregorianCalendar and JulianCalendar.
The following code example uses the SpecifyKind method to demonstrate how the Kind
property influences the ToLocalTime and ToUniversalTime conversion methods.
Option Explicit
Dim DateTime
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime", ,1979, 7, 28)
MsgBox DateTime.ToString()
Set DateTime = Nothing
DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,
Int32) Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day,
hour, minute, and second.
Set object = DotNetFactory.CreateInstance(
"System.DateTime", , year, month, day, hour, minute, second )
Parameter Description
year The year (1 through 9999).
month The month (1 through 12).
day The day (1 through the number of days in month).
hour The hours (0 through 23).
17. Chapter 14 Scripting Quicktest Professional Page 17
Dani Vainstein DotNetFactory Page 17 of 151
minute The minutes (0 through 59).
second The seconds (0 through 59).
System.DateTime object
ArgumentOutOfRangeException .
year is less than 1 or greater than 9999
month is less than 1 or greater than 12.
day is less than 1 or greater than the number of days in month.
hour is less than 0 or greater than 23.
minute is less than 0 or greater than 59.
second is less than 0 or greater than 59.
ArgumentException - The specified parameters evaluate to less than MinValue or
more than MaxValue.
The Kind property is initialized to Unspecified.
The following code example demonstrates one of the DateTime constructors.
Option Explicit
Dim DateTime
Set DateTime = _
DotNetFactory.CreateInstance( "System.DateTime", ,1979, 7, 28, 12, 23, 32 )
Print DateTime.ToString
Print DateTime.ToString( "F" )
Print DateTime.ToString( "R" )
Print DateTime.ToString( "G" )
Set DateTime = Nothing
DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,
Int32, Calendar ) Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day,
hour, minute, and second for the specified calendar.
Set object = DotNetFactory.CreateInstance(
18. Chapter 14 Scripting Quicktest Professional Page 18
Dani Vainstein DotNetFactory Page 18 of 151
"System.DateTime", , year, month, day, hour, minute, second, calendar )
Parameter Description
year The year (1 through 9999).
month The month (1 through 12).
day The day (1 through the number of days in month).
hour The hours (0 through 23).
minute The minutes (0 through 59).
second The seconds (0 through 59).
calendar The Calendar that applies to this DateTime.
System.DateTime object
ArgumentOutOfRangeException .
year is less than 1 or greater than 9999
month is less than 1 or greater than 12.
day is less than 1 or greater than the number of days in month.
hour is less than 0 or greater than 23.
minute is less than 0 or greater than 59.
second is less than 0 or greater than 59.
ArgumentException - The specified parameters evaluate to less than MinValue or
more than MaxValue.
ArgumentNullException - calendar is a null reference (Nothing in Visual Basic).
The Kind property is initialized to Unspecified.
The allowable values for year, month, and day depend on calendar. An exception is
thrown if the specified date and time cannot be expressed using calendar.
The System.Globalization namespace provides several calendars including
GregorianCalendar and JulianCalendar.
The following code example demonstrates one of the DateTime constructors.
Option Explicit
Const HEBREW_CAL = "System.Globalization.HebrewCalendar"
Dim Datetime, cal
Set cal = DotNetFactory.CreateInstance( HEBREW_CAL, "System" )
Set DateTime = DotNetFactory.CreateInstance( _
"System.DateTime", , 5767, 3, 14, 4, 10, 5, cal )
MsgBox DateTime.ToString( "F" )
Set DateTime = Nothing: Set cal = Nothing
19. Chapter 14 Scripting Quicktest Professional Page 19
Dani Vainstein DotNetFactory Page 19 of 151
DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,
Int32, DateTimeKind ) Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day,
hour, minute, second, and Coordinated Universal Time (UTC) or local time.
Set object = DotNetFactory.CreateInstance(
"System.DateTime", , year, month, day, hour, minute, second, kind )
Parameter Description
year The year (1 through 9999).
month The month (1 through 12).
day The day (1 through the number of days in month).
hour The hours (0 through 23).
minute The minutes (0 through 59).
second The seconds (0 through 59).
kind
One of the DateTimeKind values that indicates whether year, month,
day, hour, minute and second specify a local time, Coordinated
Universal Time (UTC), or neither.
System.DateTime object
ArgumentOutOfRangeException .
year is less than 1 or greater than 9999
month is less than 1 or greater than 12.
day is less than 1 or greater than the number of days in month.
hour is less than 0 or greater than 23.
minute is less than 0 or greater than 59.
second is less than 0 or greater than 59.
ArgumentException
The specified parameters evaluate to less than MinValue or more than
MaxValue.
Kind is not one of the DateTimeKind values.
20. Chapter 14 Scripting Quicktest Professional Page 20
Dani Vainstein DotNetFactory Page 20 of 151
DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,
Int32, Int32 ) Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day,
hour, minute, second and millisecond
Set object =
DotNetFactory.CreateInstance( "System.DateTime", , _
year, month, day, hour, minute, second, millisecond )
Parameter Description
year The year (1 through 9999).
month The month (1 through 12).
day The day (1 through the number of days in month).
hour The hours (0 through 23).
minute The minutes (0 through 59).
second The seconds (0 through 59).
millisecond The milliseconds (0 through 999).
System.DateTime object
ArgumentOutOfRangeException.
year is less than 1 or greater than 9999
month is less than 1 or greater than 12.
day is less than 1 or greater than the number of days in month.
hour is less than 0 or greater than 23.
minute is less than 0 or greater than 59.
second is less than 0 or greater than 59.
millisecond is less than 0 or greater than 999.
ArgumentException
The specified parameters evaluate to less than MinValue or more than
MaxValue.
DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,
Int32, Int32, Calendar ) Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day,
hour, minute, second, and millisecond for the specified calendar.
21. Chapter 14 Scripting Quicktest Professional Page 21
Dani Vainstein DotNetFactory Page 21 of 151
Set object = DotNetFactory.CreateInstance( "System.DateTime", , _
year, month, day, hour, minute, second, millisecond, calendar )
Parameter Description
year The year (1 through 9999).
month The month (1 through 12).
day The day (1 through the number of days in month).
hour The hours (0 through 23).
minute The minutes (0 through 59).
second The seconds (0 through 59).
millisecond The milliseconds (0 through 999).
calendar The Calendar that applies to this DateTime.
System.DateTime object
ArgumentOutOfRangeException .
year is less than 1 or greater than 9999
month is less than 1 or greater than 12.
day is less than 1 or greater than the number of days in month.
hour is less than 0 or greater than 23.
minute is less than 0 or greater than 59.
second is less than 0 or greater than 59.
millisecond is less than 0 or greater than 999.
ArgumentException - The specified parameters evaluate to less than MinValue or
more than MaxValue.
ArgumentNullException - calendar is a null reference (Nothing in Visual Basic).
The Kind property is initialized to Unspecified.
The allowable values for year, month, and day depend on calendar. An exception is
thrown if the specified date and time cannot be expressed using calendar.
The System.Globalization namespace provides several calendars including
GregorianCalendar and JulianCalendar.
DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,
Int32, Int32, DateTimeKind ) Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day,
hour, minute, second, millisecond, and Coordinated Universal Time (UTC) or local
time.
22. Chapter 14 Scripting Quicktest Professional Page 22
Dani Vainstein DotNetFactory Page 22 of 151
Set object = DotNetFactory.CreateInstance( "System.DateTime", , _
year, month, day, hour, minute, second, millisecond, kind )
Parameter Description
year The year (1 through 9999).
month The month (1 through 12).
day The day (1 through the number of days in month).
hour The hours (0 through 23).
minute The minutes (0 through 59).
second The seconds (0 through 59).
millisecond The milliseconds (0 through 999).
kind
One of the DateTimeKind values that indicates whether year, month,
day, hour, minute, second, and millisecond specify a local time,
Coordinated Universal Time (UTC), or neither.
System.DateTime object
ArgumentOutOfRangeException .
year is less than 1 or greater than 9999
month is less than 1 or greater than 12.
day is less than 1 or greater than the number of days in month.
hour is less than 0 or greater than 23.
minute is less than 0 or greater than 59.
second is less than 0 or greater than 59.
millisecond is less than 0 or greater than 999.
ArgumentException
The specified parameters evaluate to less than MinValue or more than
MaxValue.
Kind is not one of the DateTimeKind values.
DateTime.DateTime(Int32, Int32, Int32, Int32, Int32,
Int32, Int32, Calendar, DateTimeKind ) Constructor
Initializes a new instance of the DateTime structure to the specified year, month, day,
hour, minute, second, millisecond, and Coordinated Universal Time (UTC) or local
time for the specified calendar.
Set object = DotNetFactory.CreateInstance( "System.DateTime", , _
year, month, day, hour, minute, second, millisecond, calendar, kind )
23. Chapter 14 Scripting Quicktest Professional Page 23
Dani Vainstein DotNetFactory Page 23 of 151
Parameter Description
year The year (1 through 9999).
month The month (1 through 12).
day The day (1 through the number of days in month).
hour The hours (0 through 23).
minute The minutes (0 through 59).
second The seconds (0 through 59).
millisecond The milliseconds (0 through 999).
calendar The Calendar object that applies to this DateTime.
kind
One of the DateTimeKind values that indicates whether year, month,
day, hour, minute, second, and millisecond specify a local time,
Coordinated Universal Time (UTC), or neither.
System.DateTime object
ArgumentOutOfRangeException .
year is not in the range supported by calendar.month is less than 1 or greater
than 12.
month is less than 1 or greater than the number of months in calendar.
day is less than 1 or greater than the number of days in month.hour is less than
0 or greater than 23.
hour is less than 0 or greater than 23.
minute is less than 0 or greater than 59.
second is less than 0 or greater than 59.
millisecond is less than 0 or greater than 999.
ArgumentException
The specified parameters evaluate to less than MinValue or more than MaxValue.
kind is not one of the DateTimeKind values.
ArgumentNullException - calendar is a null reference (Nothing in Visual Basic).
The allowable values for year, month, and day parameters depend on the calendar
parameter. An exception is thrown if the specified date and time cannot be
expressed using calendar.
The System.Globalization namespace provides several calendars including
GregorianCalendar and JulianCalendar.
DateTime Properties
Name Description
Date Gets the date component of this instance.
Day Gets the day of the month represented by this instance.
DayOfWeek Gets the day of the week represented by this instance.
24. Chapter 14 Scripting Quicktest Professional Page 24
Dani Vainstein DotNetFactory Page 24 of 151
DayOfYear Gets the day of the year represented by this instance.
Hour Gets the hour component of the date represented by this instance.
Kind
Gets a value that indicates whether the time represented by this instance is
based on local time, Coordinated Universal Time (UTC), or neither.
Millisecond Gets the milliseconds component of the date represented by this instance.
Minute Gets the minute component of the date represented by this instance.
Month Gets the month component of the date represented by this instance.
Now
Gets a DateTime object that is set to the current date and time on this
computer, expressed as the local time.
Second Gets the seconds component of the date represented by this instance.
Ticks Gets the number of ticks that represent the date and time of this instance.
TimeOfDay Gets the time of day for this instance.
Today Gets the current date.
UtcNow
Gets a DateTime object that is set to the current date and time on this
computer, expressed as the Coordinated Universal Time (UTC).
Year Gets the year component of the date represented by this instance.
DateTime.Date Property
Gets the date component of this instance.
object.Date
A new DateTime with the same date as this instance, and the time value set to 12:00:00
midnight (00:00:00).
The following example returns the Date value of Now method
Option Explicit
Dim DateTime
Dim oToday, oFuture
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
Set oToday = DateTime.Today()
Set oFuture = oToday.AddDays( 7 )
Print "Today : " & oToday.Date()
Print "Future + 7 : " & oFuture.Date()
' ** Cleaning objects
Set DateTime = Nothing
Set oToday = Nothing : Set oFuture = Nothing
25. Chapter 14 Scripting Quicktest Professional Page 25
Dani Vainstein DotNetFactory Page 25 of 151
DateTime.Day Property
Gets the day of the month represented by this instance.
Value = object.Date
The day component, expressed as a value between 1 and 31.
The following example returns the Date value of Now method
Option Explicit
Dim DateTime
Dim oToday, oFuture
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
Set oToday = DateTime.Today()
Set oFuture = oToday.AddHours( 24 )
Print "Today : " & oToday.Day
Print "Future + 24h : " & oFuture.Day
' ** Cleaning objects
Set DateTime = Nothing
Set oToday = Nothing : Set oFuture = Nothing
DateTime.DayOfWeek Property
Gets the day of the week represented by this instance.
Value = object.DayOfWeek
26. Chapter 14 Scripting Quicktest Professional Page 26
Dani Vainstein DotNetFactory Page 26 of 151
A DayOfWeek enumerated constant that indicates the day of the week. This property
value ranges from zero, indicating Sunday, to six, indicating Saturday.
The following example returns the Date value of Now method
Option Explicit
Dim DateTime
Dim oToday, oFuture, i
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
Set oToday = DateTime.Today()
For i = 1 To 7
Set oFuture = oToday.AddDays( i )
Print oFuture.DayOfWeek.GetHashCode & " --> " & oFuture.DayOfWeek
Next
' ** Cleaning objects
Set DateTime = Nothing
Set oToday = Nothing : Set oFuture = Nothing
DateTime.DayOfYear Property
Gets the day of the year represented by this instance
object.DayOfYear
The day of the year, expressed as a value between 1 and 366.
The following example returns the Day of The year for Today
Msgbox DotNetFactory.CreateInstance( "System.DateTime" ).Today.DayOfYear
27. Chapter 14 Scripting Quicktest Professional Page 27
Dani Vainstein DotNetFactory Page 27 of 151
DateTime.Hour Property
Gets the hour component of the date represented by this instance.
object.Hour
The hour component, expressed as a value between 0 and 23.
The following code example demonstrates the Hour property.
Option Explicit
Dim moment
Set moment = DotNetFactory.CreateInstance( _
"System.DateTime",, 1999, 1, 13, 3, 57, 32, 11 _
)
Print "Year --> " & moment.Year ' ** Year gets 1999.
Print "Month --> " & moment.Month ' ** Month gets 1 (January).
Print "Day --> " & moment.Day ' ** Day gets 13.
Print "Hour --> " & moment.Hour ' ** Hour gets 3.
Print "Minute --> " & moment.Minute ' ** Minute gets 57.
Print "Second --> " & moment.Second ' ** Second gets 32.
Print "Millisecond --> " & moment.Millisecond ' ** Millisecond gets 11.
Set moment = Nothing
DateTime.Kind Property
28. Chapter 14 Scripting Quicktest Professional Page 28
Dani Vainstein DotNetFactory Page 28 of 151
Gets a value that indicates whether the time represented by this instance is based on
local time, Coordinated Universal Time (UTC), or neither.
object.Kind
One of the DateTimeKind values. The default is Unspecified.
The following example uses Item to retrieve the FolderItem object representing the
Windows folder and filtering the content
Option Explicit
Dim saveNow, saveUtcNow, myDt
Dim DateTimeKind
Set DateTimeKind = DotNetFactory.CreateInstance( "System.DateTimeKind" )
Set saveNow = DotNetFactory.CreateInstance( "System.DateTime" ).Now
Print "saveNow = " & saveNow.Kind.GetHashCode & " --> " & saveNow.Kind
Set saveUtcNow = DotNetFactory.CreateInstance( "System.DateTime" ).UtcNow
Print "saveUtcNow = " & saveUtcNow.Kind.GetHashCode & " --> " & saveUtcNow.Kind
Set myDt = _
DotNetFactory.CreateInstance( "System.DateTime" ).SpecifyKind( _
saveNow, DateTimeKind.Utc _
)
Print "myDt = " & myDt.Kind.GetHashCode & " --> " & myDt.Kind
Set myDt = DotNetFactory.CreateInstance( "System.DateTime" ).SpecifyKind( _
saveNow, DateTimeKind.Local _
)
Print "myDt = " & myDt.Kind.GetHashCode & " --> " & myDt.Kind
Set myDt = DotNetFactory.CreateInstance( "System.DateTime" ).SpecifyKind( _
saveNow, DateTimeKind.Unspecified _
)
Print "myDt = " & myDt.Kind.GetHashCode & " --> " & myDt.Kind
' ** Cleaning objects
Set DateTimeKind = Nothing : Set saveNow = Nothing
Set saveUtcNow = Nothing : Set myDt = Nothing
29. Chapter 14 Scripting Quicktest Professional Page 29
Dani Vainstein DotNetFactory Page 29 of 151
DateTime.Millisecond Property
Gets the milliseconds component of the date represented by this instance.
Value = object.Millisecond
The milliseconds component, expressed as a value between 0 and 999.
The following code example demonstrates the Millisecond property.
see : DateTime.Hour Property
DateTime.Minute Property
Gets the minute component of the date represented by this instance.
Value = object.Minute
The minute component, expressed as a value between 0 and 59.
The following code example demonstrates the Minute property.
see : DateTime.Hour Property
DateTime.Month Property
Gets the month component of the date represented by this instance
Value = object.Month
The month component, expressed as a value between 1 and 12.
The following code example demonstrates the Minute property.
see : DateTime.Hour Property
DateTime.Now Property
Gets a DateTime object that is set to the current date and time on this computer,
30. Chapter 14 Scripting Quicktest Professional Page 30
Dani Vainstein DotNetFactory Page 30 of 151
expressed as the local time.
Value = object.Now
A DateTime whose value is the current local date and time.
The following example returns the Now property.
Set oNow = DotNetFactory.CreateInstance( "System.DateTime" ).Now
DateTime.Second Property
Gets the seconds component of the date represented by this instance.
Value = object.Second
The seconds, between 0 and 59.
The following code example demonstrates the Second property.
see : DateTime.Hour Property
DateTime.Ticks Property
Gets the number of ticks that represent the date and time of this instance
Value = object.Ticks
The number of ticks that represent the date and time of this instance. The value is
between MinValue and MaxValue.
DateTime.TimeOfDay Property
Gets the time of day for this instance.
Value = object.TimeOfDay
31. Chapter 14 Scripting Quicktest Professional Page 31
Dani Vainstein DotNetFactory Page 31 of 151
A TimeSpan that represents the fraction of the day that has elapsed since midnight.
The following example uses Item to retrieve the FolderItem object representing the
Windows folder and filtering the content
Option Explicit
Dim saveNow, timeSpan
Set saveNow = DotNetFactory.CreateInstance( "System.DateTime" ).Now
Print "saveNow = " & saveNow
Set timeSpan = saveNow.TimeOfDay
Print "Time since midnight -> Hours : " & _
timeSpan.Hours & ", Minutes : " & _
timeSpan.Minutes & ", Seconds : " & timeSpan.Seconds
Set saveNow = Nothing : Set timeSpan = Nothing
DateTime.Today Property
Gets the current date..
Value = object.Today
A DateTime set to today's date, with the time component set to 00:00:00.
The following example returns the Today property.
Set oToday = DotNetFactory.CreateInstance( "System.DateTime" ).Today
DateTime.UtcNow Property
Gets a DateTime object that is set to the current date and time on this computer,
expressed as the Coordinated Universal Time (UTC).
Value = object.UtcNow
A DateTime whose value is the current UTC date and time.
32. Chapter 14 Scripting Quicktest Professional Page 32
Dani Vainstein DotNetFactory Page 32 of 151
Starting with the .NET Framework version 2.0, the return value is a DateTime whose
Kind property returns Utc.
The following example returns the UtcNow property. DateTime.DateTime( int64,
DateTimeKind ) Constructor
DateTime.Year Property
Gets the year component of the date represented by this instance.
Value = object.Year
The year, between 1 and 9999
The following code example demonstrates the Year property.
see : DateTime.Hour Property
DateTime Methods
Name Description
Add
Adds the value of the specified TimeSpan to the value of this
instance
AddDays Adds the specified number of days to the value of this instance.
AddHours Adds the specified number of hours to the value of this instance.
AddMilliseconds
Adds the specified number of milliseconds to the value of this
instance.
AddMinutes
Adds the specified number of minutes to the value of this
instance.
AddMonths
Adds the specified number of months to the value of this
instance.
AddSeconds
Adds the specified number of seconds to the value of this
instance.
AddTicks Adds the specified number of ticks to the value of this instance.
AddYears Adds the specified number of years to the value of this instance.
Compare
Compares two instances of DateTime and returns an indication of
their relative values.
CompareTo
Overloaded. Compares this instance to a specified object or value
type and returns an indication of their relative values.
DaysInMonth Returns the number of days in the specified month and year.
Equals Overloaded. Returns a value indicating whether two DateTime
objects, or a DateTime instance and another object or DateTime
33. Chapter 14 Scripting Quicktest Professional Page 33
Dani Vainstein DotNetFactory Page 33 of 151
are equal.
FromBinary
Deserializes a 64-bit binary value and recreates an original
serialized DateTime object.
FromFileTime
Converts the specified Windows file time to an equivalent local
time.
FromFileTimeUtc
Converts the specified Windows file time to an equivalent UTC
time.
GetTimeFormats
Overloaded. Converts the value of this instance to all the string
representations supported by the standard DateTime format
specifiers.
GetHashCode Returns the hash code for this instance.
GetTypeCode Returns the TypeCode for value type DateTime.
IsDaylightSavingTime
Indicates whether this instance of DateTime is within the
Daylight Saving Time range for the current time zone
IsLeapYear Returns an indication whether the specified year is a leap year.
op_Addition
Adds a specified time interval to a specified date and time,
yielding a new date and time.
op_Equality
Determines whether two specified instances of DateTime are
equal.
op_GreaterThan
Determines whether one specified DateTime is greater than
another specified DateTime.
op_GreaterThanOrEqual
Determines whether one specified DateTime is greater than or
equal to another specified DateTime.
op_Inequality
Determines whether two specified instances of DateTime are not
equal.
op_LessThan
Determines whether one specified DateTime is less than another
specified DateTime.
op_LessThanOrEqual
Determines whether one specified DateTime is less than or equal
to another specified DateTime.
op_Subtraction
Overloaded. Subtracts a specified DateTime or TimeSpan from
a specified DateTime.
Parse
Overloaded. Converts the specified string representation of a date
and time to its DateTime equivalent.
ParseExact
Overloaded. Converts the specified string representation of a date
and time to its DateTime equivalent. The format of the string
representation must match a specified format exactly.
SpecifyKind
Creates a new DateTime object that represents the same time as
the specified DateTime, but is designated in either local time,
Coordinated Universal Time (UTC), or neither, as indicated by the
specified DateTimeKind value.
Subtract
Overloaded. Subtracts the specified time or duration from this
instance.
ToBinary
Serializes the current DateTime object to a 64-bit binary value
that subsequently can be used to recreate the DateTime object.
ToFileTime
Converts the value of the current DateTime object to a Windows
file time.
34. Chapter 14 Scripting Quicktest Professional Page 34
Dani Vainstein DotNetFactory Page 34 of 151
ToFileTimeUtc
Converts the value of the current DateTime object to a Windows
file time.
ToLocalTime Converts the value of the current DateTime object to local time.
ToLongDateString
Converts the value of the current DateTime object to its
equivalent long date string representation.
ToLongTimeString
Converts the value of the current DateTime object to its
equivalent long time string representation.
ToShortDateString
Converts the value of the current DateTime object to its
equivalent short date string representation.
ToShortTimeString
Converts the value of the current DateTime object to its
equivalent short time string representation.
ToString
Overloaded. Overridden. Converts the value of the current
DateTime object to its equivalent string representation.
ToUniversalTime
Converts the value of the current DateTime object to
Coordinated Universal Time (UTC).
TryParse
Overloaded. Converts the specified string representation of a date
and time to its DateTime equivalent.
TryParseExact
Overloaded. Converts the specified string representation of a date
and time to its DateTime equivalent. The format of the string
representation must match a specified format exactly.
DateTime.Add ( TimeSpan ) Method
Adds the value of the specified TimeSpan to the value of this instance.
ArgumentOutOfRangeException - The resulting DateTime is less than MinValue or
greater than MaxValue.
Set object = instance.Add( value )
Parameter Description
value A TimeSpan that contains the interval to add.
A DateTime whose value is the sum of the date and time represented by this instance
and the time interval represented by value.
This method does not change the value of this DateTime. Instead, a new DateTime
is returned whose value is the result of this operation.
The following code example demonstrates the Add method. It calculates the day of the
week that is 36 days (864 hours) from this moment.
35. Chapter 14 Scripting Quicktest Professional Page 35
Dani Vainstein DotNetFactory Page 35 of 151
Option Explicit
Dim saveNow, duration, answer
Set saveNow = DotNetFactory.CreateInstance( "System.DateTime" ).Now
Set duration = DotNetFactory.CreateInstance( "System.TimeSpan", ,36, 0, 0, 0 )
Set answer = saveNow.Add( duration )
MsgBox answer.ToString( "dddd" )
Set saveNow = Nothing : Set duration = Nothing : Set answer = Nothing
DateTime.AddDays ( Double ) Method
Adds the specified number of days to the value of this instance.
This method does not change the value of this DateTime. Instead, a new DateTime
is returned whose value is the result of this operation.
The fractional part of value is the fractional part of a day. For example, 4.5 is
equivalent to 4 days, 12 hours, 0 minutes, 0 seconds, 0 milliseconds, and 0 ticks.
The value parameter is rounded to the nearest millisecond.
ArgumentOutOfRangeException - The resulting DateTime is less than MinValue or
greater than MaxValue.
Set dateTime = instance.AddDays( days )
Parameter Description
days
A number of whole and fractional days. The value parameter can be
negative or positive
A DateTime whose value is the sum of the date and time represented by this instance
and the number of days represented by days
The following code example demonstrates the AddDays method
Option Explicit
Dim saveNow
Set saveNow = DotNetFactory.CreateInstance( "System.DateTime" ).Now
36. Chapter 14 Scripting Quicktest Professional Page 36
Dani Vainstein DotNetFactory Page 36 of 151
Print "Today is --> " & saveNow.ToString( "D" )
Print "Tomorrow --> " & saveNow.AddDays( 1 ).ToString( "D" )
Print "Yesterday --> " & saveNow.AddDays( -1 ).ToString( "D" )
Set saveNow = Nothing
DateTime.AddHours ( Double ) Method
Adds the specified number of hours to the value of this instance.
Set dateTime = instance.AddHours( hours )
Parameter Description
hours
number of whole and fractional hours. The value parameter can be
negative or positive.
A DateTime whose value is the sum of the date and time represented by this instance
and the number of hours represented by hours.
ArgumentOutOfRangeException - The resulting DateTime is less than MinValue or
greater than MaxValue.
This method does not change the value of this DateTime. Instead, a new DateTime
is returned whose value is the result of this operation.
The fractional part of value is the fractional part of an hour. For example, 4.5 is
equivalent to 4 hours, 30 minutes, 0 seconds, 0 milliseconds, and 0 ticks..
The value parameter is rounded to the nearest millisecond.
DateTime.AddMilliseconds ( Double ) Method
Adds the specified number of milliseconds to the value of this instance.
Set object = instance.AddMilliseconds( value )
Parameter Description
37. Chapter 14 Scripting Quicktest Professional Page 37
Dani Vainstein DotNetFactory Page 37 of 151
value
A number of whole and fractional milliseconds. The value parameter can
be negative or positive. Note that this value is rounded to the nearest
integer.
A DateTime whose value is the sum of the date and time represented by this instance
and the number of milliseconds represented by value.
ArgumentOutOfRangeException - The resulting DateTime is less than MinValue or
greater than MaxValue.
This method does not change the value of this DateTime. Instead, a new
DateTime is returned whose value is the result of this operation.
The fractional part of value is the fractional part of a millisecond. For example, 4.5 is
equivalent to 4 milliseconds, and 5000 ticks, where one millisecond = 10000 ticks.
The value parameter is rounded to the nearest millisecond.
DateTime.AddMinutes ( Double ) Method
Adds the specified number of minutes to the value of this instance.
Set object = instance.AddMinutes( minutes )
Parameter Description
minutes
A number of whole and fractional minutes. The value parameter can be
negative or positive.
A DateTime whose value is the sum of the date and time represented by this instance
and the number of minutes represented by minutes.
ArgumentOutOfRangeException - The resulting DateTime is less than MinValue or
greater than MaxValue.
This method does not change the value of this DateTime. Instead, a new DateTime
is returned whose value is the result of this operation.
The fractional part of value is the fractional part of a minute. For example, 4.5 is
equivalent to 4 minutes, 30 seconds, 0 milliseconds, and 0 ticks.
The value parameter is rounded to the nearest millisecond.
DateTime.AddMonths ( Integer ) Method
Adds the specified number of months to the value of this instance.
38. Chapter 14 Scripting Quicktest Professional Page 38
Dani Vainstein DotNetFactory Page 38 of 151
Set object = instance.AddMonths( months )
Parameter Description
months A number of months. The months parameter can be negative or positive.
A DateTime whose value is the sum of the date and time represented by this instance
and months.
ArgumentOutOfRangeException
months is less than -120,000 or greater than 120,000.
The resulting DateTime is less than MinValue or greater than MaxValue.
This method does not change the value of this DateTime. Instead, a new
DateTime is returned whose value is the result of this operation.
The AddMonths method calculates the resulting month and year, taking into
account leap years and the number of days in a month, then adjusts the day part of
the resulting DateTime object. If the resulting day is not a valid day in the resulting
month, the last valid day of the resulting month is used. For example, March 31st +
1 month = April 30th. The time-of-day part of the resulting DateTime object
remains the same as this instance.
DateTime.AddSeconds ( Double ) Method
Adds the specified number of seconds to the value of this instance.
Set object = instance.AddSeconds( seconds )
Parameter Description
seconds
A number of whole and fractional seconds. The value parameter can be
negative or positive.
A DateTime whose value is the sum of the date and time represented by this instance
and the number of seconds represented by seconds.
ArgumentOutOfRangeException - The resulting DateTime is less than MinValue or
greater than MaxValue.
This method does not change the value of this DateTime. Instead, a new DateTime
is returned whose value is the result of this operation.
39. Chapter 14 Scripting Quicktest Professional Page 39
Dani Vainstein DotNetFactory Page 39 of 151
A The fractional part of value is the fractional part of a second. For example, 4.5 is
equivalent to 4 seconds, 500 milliseconds, and 0 ticks.
The value parameter is rounded to the nearest millisecond.
DateTime.AddTicks ( Long ) Method
Adds the specified number of ticks to the value of this instance.
Set object = instance.AddTicks( ticks )
Parameter Description
ticks
A number of 100-nanosecond ticks. The value parameter can be positive
or negative.
A DateTime whose value is the sum of the date and time represented by this
instance and the time represented by ticks.
ArgumentOutOfRangeException - The resulting DateTime is less than MinValue or
greater than MaxValue.
This method does not change the value of this DateTime. Instead, a new DateTime
is returned whose value is the result of this operation.
DateTime.AddYears ( Integer ) Method
Adds the specified number of years to the value of this instance.
Set object = instance.AddYears( years )
Parameter Description
years A number of years. The value parameter can be negative or positive.
A DateTime whose value is the sum of the date and time represented by this instance
and the number of years represented by years.
ArgumentOutOfRangeException - The resulting DateTime is less than MinValue or
greater than MaxValue.
40. Chapter 14 Scripting Quicktest Professional Page 40
Dani Vainstein DotNetFactory Page 40 of 151
This method does not change the value of this DateTime. Instead, a new DateTime
is returned whose value is the result of this operation.
The AddYears method calculates the resulting year taking into account leap years.
The month and time-of-day part of the resulting DateTime object remains the same
as this instance.
DateTime.Compare ( DateTime, DateTime ) Method
Compares two instances of DateTime and returns an indication of their relative values.
returnValue = instance.Compare( dt1, dt2 )
Parameter Description
dt1 The first DateTime.
dt2 The second DateTime.
A signed number indicating the relative values of dt1 and dt2
Less than zero - dt1 is less than dt2.
Zero - dt1 equals dt2
Greater than zero - dt1 is greater than dt2.
Before comparing DateTime objects, insure that the objects represent times in the
same time zone.
The following code example demonstrates Compare.
Option Explicit
Dim dt1, dt2, DateTime
Set dt1 = DotNetFactory.CreateInstance( "System.DateTime", ,100 )
Set dt2 = DotNetFactory.CreateInstance( "System.DateTime", ,300 )
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
If DateTime.Compare( dt1, dt2 ) > 0 Then
Print "dt1 > dt2"
End If
If DateTime.Compare( dt1, dt2 ) = 0 Then
Print "dt1 = dt2"
End If
If DateTime.Compare( dt1, dt2 ) < 0 Then
Print "dt1 < dt2"
End If
DateTime.CompareTo ( DateTime ) Method
41. Chapter 14 Scripting Quicktest Professional Page 41
Dani Vainstein DotNetFactory Page 41 of 151
Compares this instance to a specified DateTime object and returns an indication of their
relative values.
instance.CompareTo( value )
Parameter Description
value A DateTime object to compare.
A signed number indicating the relative values of this instance and the value parameter.
Less than zero - This instance is less than value
Zero - This instance is equal to value.
Greater than zero - This instance is greater than value.
This method implements the System.IComparable interface and performs slightly
better than the DateTime.CompareTo method because it does not have to convert
the value parameter to an object.
Before comparing DateTime objects, insure that the objects represent times in the
same time zone.
The following code example demonstrates the CompareTo method.
Option Explicit
Dim DateTime, thDay
Dim compareValue
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
Set thDay = DotNetFactory.CreateInstance( _
System.DateTime", , DateTime.Today.Year, 7, 28
)
compareValue = Cint( thDay.CompareTo( DateTime.Today ) )
If compareValue < 0 Then
Print thDay.ToString( "d" ) & " is in the past."
ElseIf compareValue = 0 Then
Print thDay.ToString( "d" ) & " is today!"
Else
Print thDay.ToString( "d" ) & " has not come yet."
End If
DateTime.DaysInMonth ( Integer, Integer ) Method
Returns the number of days in the specified month and year.
This method implements the System.IComparable interface and performs slightly
better than the DateTime.CompareTo method because it does not have to convert
the value parameter to an object.
42. Chapter 14 Scripting Quicktest Professional Page 42
Dani Vainstein DotNetFactory Page 42 of 151
Before comparing DateTime objects, insure that the objects represent times in the
same time zone.
returnValue = instance.DaysInMonth( year, month )
Parameter Description
year The year.
month The month (a number ranging from 1 to 12).
The number of days in month for the specified year. For example, if month equals 2
for February, the return value is 28 or 29 depending upon whether year is a leap
year.
ArgumentOutOfRangeException
month is less than 1 or greater than 12.
year is less than 1 or greater than 9999.
The following code example demonstrates the DaysInMonth method.
Option Explicit
Const CULTURE_INFO = "System.Globalization.CultureInfo"
Dim DateTime, Info
Dim arrInfo, i, nMonth
Private Sub PrintData( ByVal info, ByRef DateTime, ByVal monthIndex )
Const FMT = "{0} - {1} --> {2} has {3} Days."
Dim monthStr, engName, nativeName, daysInMon
Dim sb
monthStr= info.DateTimeFormat.MonthNames.GetValue( monthIndex - 1 )
engName = info.EnglishName
nativeName = info.NativeName
daysInMon= DateTime.DaysInMonth( DateTime.Today.Year, monthIndex )
Set sb = DotNetFactory.CreateInstance( "System.Text.StringBuilder" )
sb.AppendFormat FMT, engName, nativeName, monthStr, daysInMon
Print sb.ToString
Set sb = Nothing
End Sub
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
arrInfo = Array( "es-AR", "hi-IN", "de-DE", "fi-FI" )
For i = LBound( arrInfo ) To UBound( arrInfo )
Set info = DotNetFactory.CreateInstance( CULTURE_INFO, "System", arrInfo( i ) )
For nMonth = 1 To 12
Call PrintData( info, DateTime, nMonth )
Next
Next
43. Chapter 14 Scripting Quicktest Professional Page 43
Dani Vainstein DotNetFactory Page 43 of 151
Set Info = Nothing : Set DateTime = Nothing
44. Chapter 14 Scripting Quicktest Professional Page 44
Dani Vainstein DotNetFactory Page 44 of 151
45. Chapter 14 Scripting Quicktest Professional Page 45
Dani Vainstein DotNetFactory Page 45 of 151
DateTime.Equals ( DateTime ) Method
Returns a value indicating whether this instance is equal to the specified DateTime
instance.
returnValue = instance.Equals( value )
Parameter Description
value A DateTime instance to compare to this instance.
true if the value parameter equals the value of this instance; otherwise, false.
This method implements the System.IEquatable interface, and performs slightly
better than the Equals method because the value parameter does not have to be
converted to an object.
The following code example demonstrates the Equals method.
Option Explicit
Dim one, two, three
Dim result
Set one = DotNetFactory.CreateInstance( "System.DateTime" ).UtcNow
Set two = DotNetFactory.CreateInstance( "System.DateTime" ).Now
Set three = one
result = one.Equals(two)
Print "The result of comparing DateTime object one and two is: " & result
result = one.Equals(three)
Print "The result of comparing DateTime object one and three is: " & result
Set one = Nothing : Set two = Nothing : Set three = Nothing
DateTime.Equals ( DateTime, DateTime ) Method
Returns a value indicating whether two instances of DateTime are equal.
ReturnValue = instance.Equals( t1, t2 )
46. Chapter 14 Scripting Quicktest Professional Page 46
Dani Vainstein DotNetFactory Page 46 of 151
Parameter Description
t1 The first DateTime instance.
t2 The second DateTime instance.
true if the two DateTime values are equal; otherwise, false.
This method implements the System.IEquatable interface, and performs
slightly better than the Equals method because the value parameter does
not have to be converted to an object.
The following code example demonstrates the Equals method.
Option Explicit
Dim today1, today2, tomorrow, DateTime
Dim todayEqualsToday, todayEqualsTomorrow
Set DateTime = DotNetFactory.CreateInstance("System.DateTime")
Set today1 = DotNetFactory.CreateInstance("System.DateTime",, DateTime.Today.Ticks )
Set today2 = DotNetFactory.CreateInstance("System.DateTime",, DateTime.Today.Ticks )
Set tomorrow = DotNetFactory.CreateInstance( "System.DateTime",, _
DateTime.Today.AddDays(1).Ticks _
)
' ** todayEqualsToday gets true.
todayEqualsToday = DateTime.Equals( today1, today2 )
' ** todayEqualsTomorrow gets false.
todayEqualsTomorrow = DateTime.Equals(today1, tomorrow)
Set today1 = Nothing : Set today2 = Nothing : Set tomorrow = Nothing
Set DateTime = Nothing
DateTime.FromBinary ( Long ) Method
Deserializes a 64-bit binary value and recreates an original serialized DateTime object
instance.FromBinary( dateData )
Parameter Description
dateData
A 64-bit signed integer that encodes the Kind property in a 2-bit field
and the Ticks property in a 62-bit field
A DateTime object that is equivalent to the DateTime object that was serialized by
the ToBinary method
47. Chapter 14 Scripting Quicktest Professional Page 47
Dani Vainstein DotNetFactory Page 47 of 151
ArgumentException - dateData is less than MinValue or greater than MaxValue.
Use the ToBinary method to convert the value of the current DateTime object to a
binary value. Subsequently, use the binary value and the FromBinary method to
recreate the original DateTime object.
A local time, which is a Coordinated Universal Time adjusted to the local time zone,
is represented by a DateTime structure whose Kind property has the value Local. If
a local DateTime object is serialized in one time zone by the ToBinary method and
deserialized in a different time zone by the FromBinary method, the local time
represented by the resulting DateTime object is automatically adjusted to the
second time zone.
For example, consider a DateTime object that represents a local time of 3 P.M. An
application executing in a western time zone uses the ToBinary method to convert
that DateTime object to a binary value, then another application executing in a time
zone three hours east of the original one uses the FromBinary method to convert
the binary value to a new DateTime object. The value of the new DateTime object
is 6 P.M., which represents the same point in time as the original 3 P.M. value, but is
adjusted to local time in the eastern time zone.
DateTime.FromFileTime ( Long ) Method
Converts the specified Windows file time to an equivalent local time.
Set object = instance.FromFileTime( fileTime )
Parameter Description
fileTime A Windows file time expressed in ticks.
A DateTime object that represents a local time equivalent to the date and time
represented by the fileTime parameter.
ArgumentOutOfRangeException - fileTime is less than 0 or represents a time greater
than MaxValue.
A Windows file time is a 64-bit value that represents the number of 100-nanosecond
intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.)
Coordinated Universal Time (UTC). Windows uses a file time to record when an
application creates, accesses, or writes to a file.
The fileTime parameter specifies a file time expressed in 100-nanosecond ticks.
Starting with the .NET Framework version 2.0, the return value is a DateTime
whose Kind property is Local.
The following code example demonstrates the FromFileTime method.
Option Explicit
48. Chapter 14 Scripting Quicktest Professional Page 48
Dani Vainstein DotNetFactory Page 48 of 151
Dim dteNow, DateTime
Dim fCreationTime, fAge, LongNum
Set LongNum = DotNetFactory.CreateInstance( "System.Int64" )
Set LongNum = LongNum.Parse( "126879894987978697" )
Set dteNow = DotNetFactory.CreateInstance( "System.DateTime" ).Now
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
Set fCreationTime = DateTime.FromFileTime( LongNum )
Set fAge = dteNow.Subtract( fCreationTime )
Print fAge.Days & _
" Days, " & fAge.Hours & " Hours, and " & fAge.Minutes & " Minutes."
Print "TotalDays --> " & fAge.TotalDays
Set fAge = Nothing : Set fCreationTime = Nothing : Set dteNow = Nothing
Set LongNum = Nothing
DateTime.FromFileTimeUtc ( Long ) Method
Converts the specified Windows file time to an equivalent UTC time.
Set object = instance.FromFileTimeUtc( fileTime )
Parameter Description
fileTime A Windows file time expressed in ticks.
A DateTime object that represents a UTC time equivalent to the date and time
represented by the fileTime parameter
ArgumentOutOfRangeException - fileTime is less than 0 or represents a time greater
than MaxValue.
A Windows file time is a 64-bit value that represents the number of 100-nanosecond
intervals that have elapsed since 12:00 midnight, January 1, 1601 A.D. (C.E.)
Coordinated Universal Time (UTC). Windows uses a file time to record when an
application creates, accesses, or writes to a file.
The fileTime parameter specifies a file time expressed in 100-nanosecond ticks.
Starting with the .NET Framework version 2.0, the return value is a DateTime
whose Kind property is Utc.
49. Chapter 14 Scripting Quicktest Professional Page 49
Dani Vainstein DotNetFactory Page 49 of 151
DateTime.GetTimeFormats Method
Name Description
GetTimeFormats()
Converts the value of this instance to all the string
representations supported by the standard DateTime
format specifiers.
DateTime.GetDateTimeFormats
(Char)
Converts the value of this instance to all the string
representations supported by the specified standard
DateTime format specifier.
DateTime.GetDateTimeFormats
(IFormatProvider)
Converts the value of this instance to all the string
representations supported by the standard DateTime
format specifiers and the specified culture-specific
formatting information.
DateTime.GetDateTimeFormats
(Char, IFormatProvider)
Converts the value of this instance to all the string
representations supported by the specified standard
DateTime format specifier and culture-specific
formatting information.
DateTime.GetTimeFormats () Method
Converts the value of this instance to all the string representations supported by the
standard DateTime format specifiers.
Set objectArray = instance.GetTimeFormats()
A string array where each element is the representation of the value of this instance
formatted with one of the standard DateTime formatting specifiers.
Each element of the return value is formatted using information from the current
culture. For more information about culture-specific formatting information for the
current culture, see CultureInfo.CurrentCulture.
For For more information about the standard formatting specifiers
http://msdn2.microsoft.com/en-
us/library/system.globalization.datetimeformatinfo.aspx
The following code example demonstrates the GetDateTimeFormats method.
Option Explicit
Dim july28Formats, july28
Dim nFormat
Set july28 = DotNetFactory.CreateInstance( _
"System.DateTime",, 1979, 7, 28, 5, 23, 15, 16 _
)
Set july28Formats = july28.GetDateTimeFormats()
' ** Print out july28 in all DateTime formats using the default culture.
50. Chapter 14 Scripting Quicktest Professional Page 50
Dani Vainstein DotNetFactory Page 50 of 151
For nFormat = 0 To july28Formats.Length - 1
Print july28Formats.GetValue( CLng( nFormat ) )
Next
Set july28Formats = Nothing: Set july28 = Nothing
DateTime.GetTimeFormats ( Char ) Method
Converts the value of this instance to all the string representations supported by the
specified standard DateTime format specifier.
Set objectArray = instance.GetTimeFormats( format )
Parameter Description
format A Standard DateTime format string or a Custom DateTime Format String
51. Chapter 14 Scripting Quicktest Professional Page 51
Dani Vainstein DotNetFactory Page 51 of 151
A string array where each element is the representation of the value of this instance
formatted with the format standard DateTime formatting specifier.
Each element of the return value is formatted using information from the current
culture. For more information about culture-specific formatting information for the
current culture, see CultureInfo.CurrentCulture.
For For more information about the standard formatting specifiers
http://msdn2.microsoft.com/en-
us/library/system.globalization.datetimeformatinfo.aspx
The following code example demonstrates the GetDateTimeFormats method.
Option Explicit
Dim july28, sysChar
Dim nFormat
Set july28 = DotNetFactory.CreateInstance( _
"System.DateTime",, 1979, 7, 28, 5, 23, 15, 16 _
)
Set sysChar = DotNetFactory.CreateInstance( "System.Char" ).Parse( "R" )
' ** Get the RFC1123 date formats
Set July28Formats = july28.GetDateTimeFormats( sysChar )
' ** Print out july28 in various RFC1123 formats
For nFormat = 0 To July28Formats.Length - 1
Print July28Formats.GetValue( CLng( nFormat ) )
Next
Set July28Formats = Nothing : Set july28 = Nothing : Set sysChar = Nothing
DateTime.GetTimeFormats ( IFormatProvider ) Method
Converts the value of this instance to all the string representations supported by the
standard DateTime format specifiers and the specified culture-specific formatting
information.
Set objectArray = instance.GetTimeFormats( provider )
Parameter Description
provider
An IFormatProvider that supplies culture-specific formatting
information about this instance.
52. Chapter 14 Scripting Quicktest Professional Page 52
Dani Vainstein DotNetFactory Page 52 of 151
A string array where each element is the representation of the value of this instance
formatted with one of the standard DateTime formatting specifiers.
Each element of the return value is formatted using culture-specific information
supplied by provider.
For For more information about the standard formatting specifiers
http://msdn2.microsoft.com/en-
us/library/system.globalization.datetimeformatinfo.aspx
The following code example demonstrates the GetDateTimeFormats method.
Option Explicit
Const CULTURE_INFO = "System.Globalization.CultureInfo"
Dim arabicJuly28Formats, july28, culture
Dim nFormat
Set july28 = DotNetFactory.CreateInstance( _
"System.DateTime",, 1979, 7, 28, 5, 23, 15, 16 _
)
Set culture = DotNetFactory.CreateInstance( CULTURE_INFO, "System", "ar-EG", True )
' ** Get the short date formats using the "ar-EG" culture.
Set arabicJuly28Formats = july28.GetDateTimeFormats( culture )
Print "Starting DateTiume Formats for --> " & _
culture.EnglishName & ", " & culture.NativeName
For nFormat = 0 To arabicJuly28Formats.Length – 1 Step 2
Print arabicJuly28Formats.GetValue( CLng( nFormat ) )
Next
Set arabicJuly28Formats = Nothing : Set july28 = Nothing : Set culture = Nothing
53. Chapter 14 Scripting Quicktest Professional Page 53
Dani Vainstein DotNetFactory Page 53 of 151
DateTime.GetTimeFormats ( Char, IFormatProvider )
Method
Converts the value of this instance to all the string representations supported by the
standard DateTime format specifiers and the specified culture-specific formatting
information.
Set objectArray = instance.GetTimeFormats( format, provider )
Parameter Description
format A Standard DateTime format string or a Custom DateTime Format String
provider
An IFormatProvider that supplies culture-specific formatting
information about this instance.
A string array where each element is the representation of the value of this instance
formatted with one of the standard DateTime formatting specifiers.
Each element of the return value is formatted using culture-specific information
supplied by provider.
For For more information about the standard formatting specifiers
54. Chapter 14 Scripting Quicktest Professional Page 54
Dani Vainstein DotNetFactory Page 54 of 151
http://msdn2.microsoft.com/en-
us/library/system.globalization.datetimeformatinfo.aspx
The following code example demonstrates the GetDateTimeFormats method.
Option Explicit
Const CULTURE_INFO = "System.Globalization.CultureInfo"
Dim frenchJuly28Formats, july28, culture, sysChar
Dim nFormat
Set july28 = DotNetFactory.CreateInstance( _
"System.DateTime",, 1979, 7, 28, 5, 23, 15, 16 _
)
Set sysChar = DotNetFactory.CreateInstance( "System.Char" ).Parse( "f" )
Set culture = DotNetFactory.CreateInstance( CULTURE_INFO, "System", "fr-FR", True )
' ** Get the short date formats using the "fr-FR" culture.
Set frenchJuly28Formats = july28.GetDateTimeFormats( sysChar, culture )
' ** Print out july28 in various formats using "fr-FR" culture.
Print "Starting fr-FR formats..."
For nFormat = 0 To frenchJuly28Formats.Length - 1
Print frenchJuly28Formats.GetValue( CLng( nFormat ) )
Next
Set frenchJuly28Formats = Nothing : Set july28 = Nothing
DateTime.GetHashCode () Method
Returns the hash code for this instance.
returnValue = instance.GetHashCode()
55. Chapter 14 Scripting Quicktest Professional Page 55
Dani Vainstein DotNetFactory Page 55 of 151
A 32-bit signed integer hash code.
The following code example demonstrates the GetHashCode method.
Option Explicit
Dim SystemTime
Set SystemTime = DotNetFactory.CreateInstance( "System.DateTime" ).Today
Print "GetTypeCode --> " & SystemTime.GetTypeCode
Print "GetType --> " & SystemTime.GetType
Print "GetHashCode.GetType --> " & SystemTime.GetHashCode.GetType
Print "GetHashCode --> " & SystemTime.GetHashCode
Set SystemTime = Nothing
DateTime.GetTypeCode () Method
Returns the TypeCode for value type DateTime.
instance.GetTypeCode()
The enumerated constant, TypeCode.DateTime.
The following code example demonstrates the GetTypeCode method.
DateTime.GetHashCode() Method
DateTime.IsDaylightSavingTime () Method
Indicates whether this instance of DateTime is within the Daylight Saving Time range
for the current time zone.
instance.IsDaylightSavingTime ()
true if Kind is Local or Unspecified and the value of this instance of DateTime is
within the Daylight Saving Time range for the current time zone. false if Kind is Utc.
56. Chapter 14 Scripting Quicktest Professional Page 56
Dani Vainstein DotNetFactory Page 56 of 151
DateTime.IsLeapYear ( Integer ) Method
Returns an indication whether the specified year is a leap year.
instance.IsLeapYear( year )
Parameter Description
year A 4-digit year.
true if year is a leap year; otherwise, false.
ArgumentOutOfRangeException - year is less than 1 or greater than 9999.
year is specified as a 4-digit base 10 number; for example, 1996.
DateTime.op_Addition ( DateTime, TimeSpan ) Method
Adds a specified time interval to a specified date and time, yielding a new date and time.
instance.op_Addition( d, t )
Parameter Description
d A DateTime object
t A TimeSpan object
A DateTime that is the sum of the values of d and t.
ArgumentOutOfRangeException - The resulting DateTime is less than MinValue or
greater than MaxValue.
The following code example demonstrates the addition operator.
Option Explicit
Dim dTime, tSpan, result, DateTime
Set dTime = DotNetFactory.CreateInstance( "System.DateTime",,1980, 8, 5 )
' ** tSpan is 17 days, 4 hours, 2 minutes and 1 second.
57. Chapter 14 Scripting Quicktest Professional Page 57
Dani Vainstein DotNetFactory Page 57 of 151
Set tSpan = DotNetFactory.CreateInstance( "System.TimeSpan",,17, 4, 2, 1 )
' ** Result gets 8/22/1980 4:02:01 AM.
Set DateTime = DotNetFactory.CreateInstance( "System.DateTime" )
Set result = DateTime.op_Addition( dTime, tSpan )
Msgbox result.ToString( "G" )
Set result = Nothing : Set tSpan = Nothing : Set dTime = Nothing
DateTime.op_Equality ( DateTime, DateTime ) Method
Determines whether two specified instances of DateTime are equal.
instance.op_Equality( d1, d2 )
Parameter Description
d1 A DateTime object
d2 A DateTime object
true if d1 and d2 represent the same date and time; otherwise, false.
The following code example demonstrates the equality operator.
Option Explicit
Dim april19, otherDate
Dim areEqual
Set april19 = DotNetFactory.CreateInstance( "System.DateTime",,2001, 4, 19 )
Set otherDate = DotNetFactory.CreateInstance( "System.DateTime",,1991, 6, 5 )
' ** areEqual gets false.
areEqual = DotNetFactory.CreateInstance( _
"System.DateTime").op_Equality( april19, otherDate )
Set otherDate = DotNetFactory.CreateInstance( "System.DateTime",,2001, 4, 19)
' ** areEqual gets true.
areEqual = DotNetFactory.CreateInstance( _
"System.DateTime").op_Equality( april19, otherDate )
Set otherDate = Nothing : Set april19 = Nothing
DateTime.op_GreaterThan ( DateTime, DateTime ) Method
58. Chapter 14 Scripting Quicktest Professional Page 58
Dani Vainstein DotNetFactory Page 58 of 151
Determines whether one specified DateTime is greater than another specified
DateTime.
instance.op_GreaterThan( t1, t2 )
Parameter Description
t1 A DateTime object
t2 A DateTime object
true if t1 is greater than t2; otherwise, false.
DateTime.op_GreaterThanOrEqual ( DateTime, DateTime )
Method
Determines whether one specified DateTime is greater than or equal to another
specified
instance.op_GreaterThanOrEqual( t1, t2 )
Parameter Description
t1 A DateTime object
t2 A DateTime object
true if t1 is greater than or equal to t2; otherwise, false.
DateTime.op_Inequality ( DateTime, DateTime ) Method
Determines whether two specified instances of DateTime are not equal.
instance.op_Equality( d1, d2 )
Parameter Description
d1 A DateTime object
d2 A DateTime object
59. Chapter 14 Scripting Quicktest Professional Page 59
Dani Vainstein DotNetFactory Page 59 of 151
true if d1 and d2 do not represent the same date and time; otherwise, false.
DateTime.op_LessThan ( DateTime, DateTime ) Method
Determines whether one specified DateTime is less than another specified DateTime
instance.op_LessThan( t1, t2 )
Parameter Description
t1 A DateTime object
t2 A DateTime object
true if t1 is less than t2; otherwise, false.
DateTime.op_LessThanOrEqual ( DateTime, DateTime )
Method
Determines whether one specified DateTime is less than or equal to another specified
DateTime
instance.op_LessThanOrEqual( t1, t2 )
Parameter Description
t1 A DateTime object
t2 A DateTime object
true if t1 is less than or equal to t2; otherwise, false.
DateTime.op_Subtraction Method
Name Description
DateTime.op_Subtraction
(DateTime, DateTime)
Subtracts a specified date and time from another
specified date and time, yielding a time interval.
DateTime.op_Subtraction
(DateTime, TimeSpan)
Subtracts a specified time interval from a specified
date and time, yielding a new date and time.
DateTime.op_Subtraction ( DateTime, DateTime ) Method