TestPlan dateTimeBinOp
Document

dateTimeBinOp

by Group Public on Monday June 22 2009 @ 10:14:55 (1/1 Points)

API ↪Reference ✑ Reply ✓ Stick It ✗ Ditch It ⚐ Tag It

The dateTimeBinOp function provides the ability to add a duration to a DateTime object and to obtain durations from two DateTime objects.

Adding Duration

For syntactic reasons duration operations are always expressed as addition, such as:

set %Time24H% as dateTimeBinOp %Now% + PT24H

If you need to subtract a duration, rather than add it, then simply use the negative form of the duration.

set %Time24H% as dateTimeBinOp %Now% + -PT24H

Duration Syntax

The duration syntax allows you to express years, months, days, hours, minutes, and seconds. It is the standard XML and ISO8601 datatype format with the syntax P#Y#M#DT#H#M#S.

The first three # fields are years, months and days respectively. The second three are hours, minutes, and seconds. Simply replace the # with the value you wish. Note that seconds can be expressed with a decimal for arbitrary precision.

You do not need to specify zero for parts you don't need, you can simply omit them instead. Some examples are below:

  • P2D : 2 Days
  • PT11H : 11 Hours
  • -P2MT10S : Negative 2 months and 10 seconds

Note that although the years, months, and days need not be specified you will still need to use the T to indicate you are specifying the time component.

Subtracting DateTime

The other operation is the ability to subtract one date from another to get the duration between those dates. The result will be a Duration object which can be used like shown above.

set %Duration% as dateTimeBinOp 2009-10-11 - 2009-10-10
Notice %Duration%

Notice that the string form of the duration obtained in this fashion will often include many optional time parts. Also notice that it will tend to indicate number of days, rather than months or years.

It is important to note that 31Days is not the same as a month. A duration expressed as P1M is thus quite different from a duration expressed as P31D. Depending on which DateTime you add it to each may give a different result.

Millisecond Difference

If you'd prefer to have a more concrete value expressing the difference between the dates, you may wish to use the -ms operator. For more flexibility however can use the durationAs function.

The -ms operator returns the number of milliseconds between two dates.

set %MS% as dateTimeBinOp 2001-01-01T10:50:30 -ms 2001-01-01T10:50:15
Notice %MS%
set %MS% as dateTimeBinOp 2001-01-01T10:50:30 -ms 2001-01-01T10:50:35
Notice %MS%
© 2008-2010 edA-qa mort-ora-y
Using Persephone and TestPlan
Tag: