Home / InterSystems SQL Reference / SQL Functions / DAYNAME

InterSystems SQL Reference
Previous section           Next section
InterSystems: The power behind what matters   

A date function that returns the name of the day of the week for a date expression.
{fn DAYNAME(date-expression)}
date-expression An expression that evaluates to either an InterSystems IRIS 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.
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 an InterSystems IRIS date integer, a $HOROLOG or $ZTIMESTAMP value, an ODBC format date string, or a timestamp.
A date-expression timestamp can be either data type %Library.PosixTime (an encoded 64-bit signed integer), or data type %Library.TimeStamp (yyyy-mm-dd hh:mm:ss.fff).
The time portion of the timestamp is not evaluated and can be omitted.
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() method call:
The following examples both return the character string Wednesday because the day of the date (February 21, 2018) is a Wednesday. The first example takes a timestamp string:
SELECT {fn DAYNAME('2018-02-21 12:35:46')} AS Weekday
The second example takes an InterSystems IRIS date integer:
SELECT {fn DAYNAME(64700)} 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 2017 was not a leap year):
   SET testdate="2017-02-29"
   &sql(SELECT {fn DAYNAME(:testdate)}
   INTO :a)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,"returns: ",a }
The following embedded SQL example shows how DAYNAME responds to an invalid date (the year 1835 is too early for InterSystems SQL):
   SET testdate="1835-02-19"
   &sql(SELECT {fn DAYNAME(:testdate)}
   INTO :a)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,"returns: ",a }
See Also

Previous section           Next section
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-04-10 14:45:57