Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs
    • SQL FAQ’s

MySQL DAYOFWEEK

by suresh

MySQL DAYOFWEEK function is one of the MySQL Date Functions, used to return the weekday index value of the given date. This DAYOFWEEK function returns value from 1 to 7 where 1 = Sunday, 2 = Monday, ….. 7 = Sunday.

Let us see how to use this DAYOFWEEK function to get the weekday or Day of Week in MySQL from an expression with example. The basic syntax of the DAYOFWEEK() Function in MySQL is as shown below:

DAYOFWEEK(date or expression);

MySQL DAYOFWEEK function Example

These examples help you understand the use of the dayofweek function. Here, we are returning the Weekday index number from the date expression, and the Date & time expression.

SELECT DAYOFWEEK('2018-12-30');

SELECT DAYOFWEEK('2018-12-31');

SELECT DAYOFWEEK('2018-12-15 03:22:19');

OUTPUT

MySQL DAYOFWEEK Function 1

Let us see another example of the MySQL DAYOFWEEK function. Here, we are returning the Weekday index number from the current date and time returned by the Now() and CURDATE() function.

SELECT DAYOFWEEK(NOW()), DAYOFWEEK(CURRENT_DATE());

OUTPUT

MySQL DAYOFWEEK Function 2

MySQL DAYOFWEEK Function Example 2

The following MySQL queries show what happens when we try to return the weekday index from 0 date format, string format, or invalid dates.

SELECT DAYOFWEEK(NOW() + 2);

SELECT DAYOFWEEK('2019-02-31');

SELECT DAYOFWEEK('0000-00-00');

OUTPUT

MySQL DAYOFWEEK Function 3

From the above screenshot, DAYOFWEEK(‘2019-02-31’); statement returned NULL because it’s an invalid date.

Within the Last Date Function statement, DAYOFWEEK(0) means, we are trying to extract the day of the week from a zero date part. That’s why it returns NULL.

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy