NEXT_DAY Vs DAYNAME Top SQL Examples

The NEXT_DAY function extracts DATE per the DAY you supplied in the SQL Query. The DAYNAME function gives you the name of the DAY. Below are the best DB2 examples.


Subscribe to receive latest posts.

  • Next_Day Function needs two parameters.

  • DATE and DAY name.

  • It gives DATE of the coming DAY (that you supplied in input).

SQL Query Example NEXT_DAY.

SELECT ship_date, NEXT_DAY(ship_date, 'SAT') 
AS next_saturday,
   NEXT_DAY(ship_date, 'SAT') - ship_date AS num_days 
FROM orders;

It calculates following Saturday Date from ship_date.

Advertisements
  • DAYNAME, DAYOFWEEK and MONTHNAME Functions need one parameter. i.e CURRENT TIMESTAMP.

SQL Query to Use Functions of DAYNAME, DAYOFWEEK, MONTHNAME.

SELECT CURRENT TIMESTAMP
,DAYNAME(CURRET TIMESTAMP)
,DAYOFWEEK(CURRENT TIMESTAMP)
,MONTHNAME(CURRENT TIMESTAMP)
FROM 
SYSIBM.SYSDUMMY1;

This SQL query extracts Day name, Day of week, and Month name.

1# DAYNAME:

Sunday, Monday,…

2# DAYOFWEEK:

1-Sunday, 2-Monday…

3# MONTHNAME:

JANUARY, FEBRUARY…

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.