Maintain-specific Standard Date and Time Functions

In this section:

Standard date and time functions are for use with non-legacy dates. For a definition of standard dates and times, see Date and Time Functions.

HHMMSS: Retrieving the Current Time (Maintain)

How to:

The HHMMSS function retrieves the current time from the operating system as an 8-character string, separating the hours, minutes, and seconds with periods.

To use this function, you must import the function library MNTUWS. For information on importing a function library, see Calling a Function.

There is also an HHMMSS function available in the reporting language. For information on this function, see HHMMSS: Retrieving the Current Time.

Syntax: How to Retrieve the Current Time

HHMMSS()

Example: Retrieving the Current Time

HHMMSS retrieves the current time from the operating system:

MAINTAIN
Module Import (mntuws);
Case Top
Compute now/a10 = hhmmss();
type "Now = <<now"
EndCase
END

The output is:

Now = 14.25.33

Initial_HHMMSS: Returning the Time the Application Was Started

How to:

The Initial_HHMMSS function returns the time when the Maintain Data application was started as an 8-character string, with embedded periods separating the hours, minutes, and seconds.

To use this function, you must import the function library MNTUWS. For details on importing this library, see Calling a Function.

Syntax: How to Retrieve the Initial Time

Initial_HHMMSS()

Initial_TODAY: Returning the Date the Application Was Started

How to:

The Initial_TODAY function returns the date in MM/DD/YY format when the Maintain Data application was started as an 8-character string with embedded slashes.

To use this function, you must import the function library MNTUWS. For details on importing this library, see Calling a Function.

Syntax: How to Retrieve the Initial Date

Initial_TODAY()

TODAY: Retrieving the Current Date (Maintain)

How to:

The TODAY function retrieves the current date from the system in the format MM/DD/YY. TODAY always returns a date that is current. Therefore, if you are running an application late at night, use TODAY. You can remove the embedded slashes using the EDIT function.

To use this function, you must import the function library MNTUWS. For information on importing this library, see Calling a Function.

There is a version of the TODAY function that is available only in the reporting language. For information on this function, see HTMTOTS or TIMETOTS: Converting a Time to a Timestamp.

Syntax: How to Retrieve the Current Date

TODAY()

Example: Retrieving the Current Date

TODAY retrieves the current date from the system:

MAINTAIN
Module Import (mntuws);
 
Case Top
Compute date1/a8 = today();
type "Date1 = <<date1"
Endcase
END

The result is:

Date1 = 07/17/02

TODAY2: Returning the Current Date

How to:

The TODAY2 function retrieves the current date from the operating system in the format MM/DD/YYYY. Use format A10 with the TODAY2 function to ensure proper results.

To use this function, you must import the function library MNTUWS. For information on importing this library, see Calling a Function.

Syntax: How to Retrieve the Current Date

TODAY2()

Example: Retrieving the Current Date

TODAY2 retrieves the current date from the system:

MAINTAIN
Module Import (mntuws);
 
Case Top
Compute date2/a10 = today2();
type "Date2 = <<date2"
Endcase
END

The result is:

Date2 = 07/17/2002

ADD: Adding Days to a Date

How to:

The ADD function adds a given number of days to a date.

Syntax: How to Add Days to a Date

ADD(date,value)

or

date.ADD(value)

where:

date
Is the date to add days to, or a field containing the date.
value
Is the number of days by which to increase the date.

This function changes the value of date.

Example: Adding Days to a Date

ADD adds 10 days to the each value in the DateVar field:

ADD(DateVar, 10)

The following are sample values for DateVar and the corresponding values for ADD(DateVar, 10):

DateVar      ADD(DateVar, 10);
-------      -----------------
12/31/1999   01/10/2000
01/01/2000   01/11/2000
01/02/2000   01/12/2000

DAY: Extracting the Day of the Month From a Date

How to:

The DAY function extracts the day of the month from a date and returns the result as an integer.

Syntax: How to Extract the Day of the Month From a Date

DAY(date);

where:

date
Is the date (in date format) from which to extract the day of the month, or a field containing the date.

Example: Extracting the Day of the Month From a Date

DAY extracts the day of the month from the DATE field:

DAY(DATE)

The following are sample values for DATE and the corresponding values for DAY(DATE):

DATE         DAY(DATE)
----         ---------
01/01/2000   1
01/02/2000   2
01/03/2000   3

JULIAN: Determining How Many Days Have Elapsed in the Year

How to:

The JULIAN function determines the number of days that have elapsed in the given year up to a given date, and returns the result as an integer.

Syntax: How to Determine How Many Days Have Elapsed in the Year

JULIAN(date);

where:

date
Is the date (in date format) for which to determine the number of days elapsed in the given year, or a field containing the date.

Example: Determining How Many Days Have Elapsed in the Year

JULIAN determines the number of days that have elapsed up to the date in the DATE field:

JULIAN(DATE)

The following are sample values for DATE and the corresponding values for JULIAN(DATE):

DATE         JULIAN(DATE)
----         ------------
01/01/2000   1
02/01/2000   32
03/01/2000   61

MONTH: Extracting the Month From a Date

How to:

The MONTH function extracts the month from a date and returns the result as an integer.

Syntax: How to Extract the Month From a Date

MONTH(date);

where:

date
Is the date (in date format) from which to extract the month, or a field containing the date.

Example: Extracting the Month From a Date

MONTH extracts the month from each value in the DATE field:

MONTH(DATE)

The following are sample values for DATE and the corresponding values for MONTH(DATE):

DATE         MONTH(DATE)
----         -----------
01/01/2000   1
02/01/2000   2
03/01/2000   3

QUARTER: Determining the Quarter

How to:

The QUARTER function determines the quarter of the year in which a date resides, and returns the result as an integer.

Syntax: How to Determine the Quarter for a Date

QUARTER(date);

where:

date
Is the date (in date format) for which to determine the quarter, or a field containing the date.

Example: Determining the Quarter for a Date

QUARTER extracts the quarter component from each value in the DATE field:

QUARTER(DATE)

The following are sample values for DATE and the corresponding values for QUARTER(DATE):

DATE         QUARTER(DATE)
----         -------------
01/01/2000   1
04/01/2000   2
07/01/2000   3

SETMDY: Setting the Value to a Date

How to:

The SETMDY function sets a value to a date based on numeric values representing a day, month, and year. SETMDY returns a 0 if the function is successful, and a negative number if the function fails.

Syntax: How to Set a Value to a Date

SETMDY(date, month, day, year);

or

date.SETMDY(month, day, year);

where:

date
Is the date, in date format, or a field containing the date.
month
Is an integer value representing a month.
day
Is an integer value representing the day of the month.
year
Is an integer value representing a year.

Example: Setting a Value to a Date

SETMDY sets the value of DateVar, which is formatted as a date that appears as wrMtrDYY (for example, Saturday, January 1, 2000):

SETMDY(DateVar, month, day, year);

The following are sample values for month, day, and year, and the corresponding dates for DateVar:

month  day   year   DateVar
-----  ---   ----   -------
04     05    1965   Monday, April 5, 1965
02     01    1997   Saturday, February 1, 1997
01     01    2000   Saturday, January 1, 2000

SUB: Subtracting a Value From a Date

How to:

The SUB function subtracts a given number of days from a date.

Syntax: How to Subtract a Value From a Date

SUB(date,value)

or

date.SUB(value)

where:

date
Is the date from which to subtract the value, or a field containing the date.
value
Is the value to subtract from the date.

Example: Subtracting Days From a Date

SUB subtracts 10 days from each value in the DateVar field.

SUB(DateVar, 10)

The following are sample values for DateVar and the corresponding values for SUB(DateVar, 10):

DateVar      SUB(DateVar, 10);
-------      -----------------
12/31/1999   12/21/2000
01/01/2000   12/22/2000
01/02/2000   12/23/2000

WEEKDAY: Determining the Day of the Week for a Date

How to:

The WEEKDAY function determines the day of the week for a date and returns the result as an integer (1=Monday, 2=Tuesday, and so on).

Syntax: How to Determine the Day of the Week for a Date

WEEKDAY(date);

where:

date
Is the date (in date format) for which to determine the weekday, or a field containing the date.

Example: Determining the Day of the Week for a Date

WEEKDAY determines the day of the week for each date in the DATE field, and stores that day as a number corresponding to a weekday:

WEEKDAY(DATE)

The following are sample values for DATE and the corresponding values for WEEKDAY(DATE):

DATE         WEEKDAY(DATE)
----         -------------
01/01/2000   6
01/02/2000   7
01/03/2000   1

YEAR: Extracting the Year From a Date

How to:

The YEAR function extracts the year from a date.

Syntax: How to Extract the Year From a Date

YEAR(date);

where:

date
Is the date from which to extract the year, or a field containing the date.

Example: Extracting a Year From a Date

YEAR extracts the year from the DATE field, and stores that year in the YEAR(DATE) field:

YEAR(DATE)

The following are sample values for DATE and the corresponding values for YEAR(DATE):

DATE          YEAR(DATE)
----          ----------
01/01/2000    2000
02/01/2001    2001
03/01/2002    2002