WEEKDAY(): Day number of the weekday from 0 to 6

SELECT WEEKDAY('2024-01-01'); # 0
SELECT WEEKDAY('2024-12-31'); # 1
SELECT WEEKDAY('2024-02-31'); # NULL
Syntax
WEEKDAY(date)
Example
SELECT WEEKDAY('2016-09-21')
Output is 2

WEEKDAY() function to get number from 0 to 6 based on Weekday in MySQL

Using CURDATE()

SELECT WEEKDAY(CURDATE())
This will return weekday in number of present ( today's ) date.

CURDATE()

For a invalid date we will get Null as output
SELECT WEEKDAY('2015-02-31')
Output is NULL
DEMO: Select date from Calendar to execute WEEKDAY()
Output of WEEKDAY() function is from 0 to 6,
0 for Monday, 1 for Tuesday .... 6 for Sunday

Yesterday today and tomorrow WEEKDAY()

This query will return WEEKDAY() number of yesterday , today and tomorrow
SELECT WEEKDAY(CURDATE()- INTERVAL 1 DAY) as yesterday,
WEEKDAY(CURDATE()) as today,
WEEKDAY(CURDATE()+ INTERVAL 1 DAY) as tomorrow;

SQL Date WEEK() : Week Number in Year( 0 to 53 ) DAYOFWEEK() : Weekday Number from 1 to 7
SQL txt file for WEEKDAY()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com

    Post your comments , suggestion , error , requirements etc here





    SQL Video Tutorials










    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer