Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see Why Migrate to InterSystems IRIS?

Times and Dates

Times and Dates

The PTIME_STRUCTPtr, PDATE_STRUCTPtr, and PTIMESTAMP_STRUCTPtr packages are used to manipulate Caché %TIME, %DATE, or %TIMESTAMP datatypes.

%TIME

Methods of the PTIME_STRUCTPtr package are used to manipulate the Caché %DATE data structure. Times are in hh:mm:ss format. For example, 5 minutes and 30 seconds after midnight would be formatted as 00:05:30. Here is a complete listing of Time methods:

new()
$time = PTIME_STRUCTPtr->new()

Create a new Time object.

get_hour()
$hour = $time->get_hour()

Return hour

get_minute()
$minute = $time->get_minute()

Return minute

get_second()
$second = $time->get_second()

Return second

set_hour()
$time->set_hour($hour)

Set hour (an integer between 0 and 23, where 0 is midnight).

set_minute()
$time->set_minute($minute)

Set minute (an integer between 0 and 59).

set_second()
$time->set_second($second)

Set second (an integer between 0 and 59).

toString()
$stringrep = $time->toString()

Convert the time to a string: hh:mm:ss.

%DATE

Methods of the PDATE_STRUCTPtr package are used to manipulate the Caché %DATE data structure. Dates are in yyyy-mm-dd format. For example, December 24, 2003 would be formatted as 2003-12-24. Here is a complete listing of Date methods:

new()
$date = PDATE_STRUCTPtr->new()

Create a new Date object.

get_year()
$year = $date->get_year()

Return year

get_month()
$month = $date->get_month()

Return month

get_day()
$day = $date->get_day()

Return day

set_year()
$date->set_year($year)

Set year (a four-digit integer).

set_month()
$date->set_month($month)

Set month (an integer between 1 and 12).

set_day()
$date->set_day($day)

Set day (an integer between 1 and the highest valid day of the month).

toString()
$stringrep = $date->toString()

Convert the date to a string: yyyy-mm-dd.

%TIMESTAMP

Methods of the PTIMESTAMP_STRUCTPtr package are used to manipulate the Caché %TIMESTAMP data structure. Timestamps are in yyyy-mm-dd<space>hh:mm:ss.fffffffff. format. For example, December 24, 2003, five minutes and 12.5 seconds after midnight, would be formatted as:

2003-12-24 00:05:12:500000000

Here is a complete listing of TimeStamp methods:

new()
$timestamp = PTIMESTAMP_STRUCTPtr->new()

Create a new Timestamp object.

get_year()
$year = $timestamp->get_year()

Return year in yyyy format.

get_month()
$month = $timestamp->get_month()

Return month in mm format.

get_day()
$day = $timestamp->get_day()

Return day in dd format.

get_hour()
$hour = $timestamp->get_hour()

Return hour in hh format.

get_minute()
$minute = $timestamp->get_minute()

Return minute in mm format.

get_second()
$second = $timestamp->get_second()

Return second in ss format.

get_fraction()
$fraction = $timestamp->get_fraction()

Return fraction of a second in fffffffff format.

set_year()
$timestamp->set_year($year)

Set year (a four-digit integer).

set_month()
$timestamp->set_month($month)

Set month (an integer between 1 and 12).

set_day()
$timestamp->set_day($day)

Set day (an integer between 1 and the highest valid day of the month).

set_hour()
$timestamp->set_hour($hour)

Set hour (an integer between 0 and 23, where 0 is midnight).

set_minute()
$timestamp->set_minute($minute)

Set minute (an integer between 0 and 59).

set_second()
$timestamp->set_second($second)

Set second (an integer between 0 and 59).

set_fraction()
$timestamp->set_fraction($fraction)

Set fraction of a second (an integer of up to nine digits).

toString()
$stringrep = $timestamp->toString()

Convert the timestamp to a string yyyy-mm-dd hh:mm:ss.fffffffff.

Feedback