DateTimeValue function

Syntax

DateTimeValue(textdatetime)

Description

Use the DateTimeValue function to derive a DateTime value from a string representing a date and time.

Parameters

Parameter Description

textdatetime

Specify a date/time value represented as text in one of three formats:

  • MM / DD / YY[YY] hh : mm : ss.ssssss [{AM|PM}]

  • MM . DD . YY[YY] hh : mm : ss.ssssss [{AM|PM}]

  • YYYY - MM - DD T hh : mm : ss[. S]TZD (that is, ISO 8601 format—for example, 1999-01-01T19:20:30.000000+0800)

In which:

  • YY[YY] is a two- or four-digit year.

  • YYYY is a four-digit year.

  • MM is a two-digit month (01 through 12).

  • DD is a two-digit day of the month (01 through 31).

  • hh is a two digits of hour (00 through 23).

  • mm is a two digits of minute (00 through 59).

  • ss is two digits of second (00 through 59).

  • ssssss is six digits of milliseconds.

  • S is milliseconds in one or up to six digits.

  • TZD is a time zone designator (Z, +/- hh : mm or +/- hhmm).

Returns

Returns a DateTime value.

Example

Both of the following examples set &Date_TIME to a DateTime value equal to October 13, 1997 10:34:25 PM.:

&Date_TIME = DateTimeValue("10/13/97 10:34:25 PM");
&Date_TIME = DateTimeValue("10/13/97 22:34:25");

Assuming the base time (as defined in PSOPTIONS) is PST, the following three examples set &Date_TIME to a DateTime value equal to 2009-12-31-22.30.40.120000 UTC:

&Date_Time = DateTimeValue("2010-01-01 06:30:40.12Z");
&Date_Time = DateTimeValue("2010-01-01 00:30:40.12-0600");
&Date_Time = DateTimeValue("2010-01-01 10:30:40.12+04:00");

Using this Function in Fields Without a Default Century Setting

This function may derive the wrong century setting if passed a two-character year and DateTimeValue is executing in a PeopleCode event not associated with a field that has a default century setting.

For example, assume that TEST_DATE is a date field with a default century setting of 10. TEST_FIELD is a field with no default century setting. If the following PeopleCode program is executing in TEST_FIELD, the date will be calculated incorrectly:

TEST_DATE = DateTimeValue("10/13/11 15:34:25");

Although TEST_DATE has a century setting, it isn’t used because the PeopleCode fired in TEST_FIELD. Instead, DateTimeValue uses the 50/50 rule and calculates the year to be 2011 (instead of 1911).