简体   繁体   中英

How to get weekday name from a date in informix sql?

I have a date column in a table which I have to return weekday name from it while I join it with another table.

Right now I get it as an int WEEKDAY(a.vila_date) weekdag

SELECT years, software, vsnr, WEEKDAY(a.vila_date) weekdag,  a.vilatime
FROM  vila a, onta v

I want a result like Monday, Tuesday, Wednesday, Thursday, Friday. Considering 1 = Monday and 0 = Sunday

You can use the TO_CHAR() function to format a DATE or DATETIME value or column into various formats including the full or abbreviated weekday name.

Example:

SELECT TODAY today, 
       WEEKDAY(TODAY) wday_num, 
       TO_CHAR(TODAY, "%a") wday_short,
       TO_CHAR(TODAY, "%A") wday_full
FROM systables 
WHERE tabid = 1;

Output:

today       06/04/2021      
wday_num    5
wday_short  Fri
wday_full   Friday

The documentation for the TO_CHAR() function can be found at https://www.ibm.com/docs/en/informix-servers/12.10?topic=dcf-char-function#ids_sqt_129 where you can also search for information on the GL_DATETIME and GL_DATE environment variable which list the formatting directives (such as "%a") that can be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM