DAYNAME
Synopsis
{fn DAYNAME(date-expression)}
Arguments
Argument | Description |
---|---|
date-expression | An expression that evaluates to either a Caché date integer, an ODBC date, or a timestamp. This expression can be the name of a column, the result of another scalar function, or a date or timestamp literal. |
Description
DAYNAME returns the name of the day that corresponds to a specified date. The returned value is a character string with a maximum length of 15. The default day names returned are: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday.
To change these default day name values, use the SET OPTION command with the WEEKDAY_NAME option.
The day name is calculated for a Caché date integer, a $HOROLOG or $ZTIMESTAMP value, an ODBC format date string, or a timestamp.
A date-expression timestamp is data type %Library.TimeStampOpens in a new tab (yyyy-mm-dd hh:mm:ss.fff).
The time portion of the timestamp is not evaluated and can be omitted. The date-expression can also be specified as data type %Library.FilemanDate, %Library.FilemanTimestamp, or %MV.Date.
DAYNAME checks that the date supplied is a valid date. The year must be between 1841 and 9999 (inclusive), the month 01 through 12, and the day appropriate for that month (for example, 02/29 is only valid on leap years). If the date is not valid, DAYNAME issues an SQLCODE -400 error (Fatal error occurred).
The same day of week information can be returned by using the DATENAME function. You can use TO_DATE to retrieve a day name or day name abbreviation with other date elements. To return an integer corresponding to the day of the week, use DAYOFWEEK DATEPART or TO_DATE.
This function can also be invoked from ObjectScript using the DAYNAME()Opens in a new tab method call:
$SYSTEM.SQL.DAYNAME(date-expression)
Examples
The following examples both return the character string Wednesday because the day of the date (February 25, 2004) is a Wednesday. The first example takes a timestamp string:
SELECT {fn DAYNAME('2004-02-25 12:35:46')} AS Weekday
The second example takes a Caché date integer:
SELECT {fn DAYNAME(59590)} AS Weekday
The following examples all return the name of the current day of the week:
SELECT {fn DAYNAME({fn NOW()})} AS Wd_Now,
{fn DAYNAME(CURRENT_DATE)} AS Wd_CurrDate,
{fn DAYNAME(CURRENT_TIMESTAMP)} AS Wd_CurrTstamp,
{fn DAYNAME($ZTIMESTAMP)} AS Wd_ZTstamp,
{fn DAYNAME($HOROLOG)} AS Wd_Horolog
Note that $ZTIMESTAMP returns Coordinated Universal Time (UTC). The other time-expression values return the local time. This may affect the DAYNAME value.
The following embedded SQL example shows how DAYNAME responds to an invalid date (the year 2001 was not a leap year):
SET testdate="2001-02-29"
&sql(SELECT {fn DAYNAME(:testdate)}
INTO :a)
IF SQLCODE'=0 {
WRITE !,"Error code ",SQLCODE }
ELSE {
WRITE !,"returns: ",a }
QUIT
The following embedded SQL example shows how DAYNAME responds to an invalid date (the year 1835 is too early for Caché SQL):
SET testdate="1835-02-19"
&sql(SELECT {fn DAYNAME(:testdate)}
INTO :a)
IF SQLCODE'=0 {
WRITE !,"Error code ",SQLCODE }
ELSE {
WRITE !,"returns: ",a }
QUIT
See Also
-
SQL functions: DATENAME, DATEPART, DAYOFMONTH, DAYOFWEEK, DAYOFYEAR, TO_DATE
-
ObjectScript function: $ZDATE
-
ObjectScript special variables: $HOROLOG, $ZTIMESTAMP