AS400 Date and Time Scalar Functions


The following are AS400 specific scalar function for returning and manipulating date/time and timestamp values.

CURDATE
Returns the current system date.

CURTIME
Returns the current system time.

CURRENT_TIMESTAMP
Returns the system current date and time as a timestamp.

DATE(X)
Returns a date interpreted from value X. X can be a date representation or an integer/long. If X is a number the date is n-1 days from jan 01, 0001.

DAY(X)
Returns the day part of X. X must be a date.

DAYOFMONTH(X)
Identical to DAY.

DAYOFWEEK(X)
Returns 1 through 7. 1 is Sunday, 7 is Saturday.

DAYOFYEAR(X)
Returns between 1 and 366 where 1 is Jan 0. X must be a date or timestamp value.

DAYS(X)
Returns the number of days +1 from JAN 01, 0001 to X.

HOUR(X)
Returns the hour part of time or timestamp X.

MICROSECOND(X)
Returns the microsecond part of timestamp or time value X.

MINUTE(X)
Returns the minutes portion of timestamp or time value X.

MONTH(X)
Returns the month number, 1 through 12, of the date or timestamp value X.

NOW()
Returns a timestamp of the time/date when the statement is executed at the server.

QUARTER(X)
Returns a number between 1 and 4 which represents the quarter of the year represented by date or timestamp X.

SECOND(X)
Returns the seconds part of time or timstamp value X.

TIME(X)
Returns the time from X. X can be a time, timestamp or string representing a time or timestamp.

TIMESTAMP(X) or TIMESTAMP(X,Y)
Returns a valid timestamp from X. X can b a string, X and Y could be strings or a Date and a Time.

WEEK(X)
Returns the week number of the date X.

YEAR(X)
Returns an integer representing the year of the date X.