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

MySQL DAYNAME Function

by suresh

MySQL DAYNAME function is one of the Date Functions, which returns the name of the weekday from a given date. For example, Monday, Tuesday, etc.

The basic syntax of the Dayname() Function in MySQL is as shown below:

DAYNAME(date or expression);

MySQL Dayname function Example

The below shown queries help you understand the use of this MySQL Day name function. Here, we are returning the weekday name or name of the weekday from the date expression, and the Date and time expression.

SELECT DAYNAME('2019-03-05');

SELECT DAYNAME('2019-03-04 10:22:59');

SELECT NOW(), DAYNAME(NOW());

OUTPUT

MySQL DAYNAME Function 1

MySQL Dayname Function Example 2

The following MySQL query shows you what happens when we try to return the weekday name from a date in string format.

Here, we are returning the name of the weekday from the current date and time returned by the Now() function, and CURDATE() function. We also used the date in YYYYMMDD format.

SELECT NOW(), DAYNAME(NOW() + 2);

SELECT CURDATE(), DAYNAME(CURDATE() + 2);

SELECT DAYNAME(20181231);

OUTPUT

MySQL DAYNAME Function 2

In this Date Function example, we are trying to return the name of the weekday from an invalid date and zero date part. That’s why it returns NULL.

SELECT DAYNAME(2018-12-41);

SELECT DAYNAME(2018-00-00);

SELECT DAYNAME(0000-00-00);

OUTPUT

MySQL DAYNAME Function 3

MySQL Dayname Example 3

In this instance, we show you how to use this MySQL Day name function on a table. Here, we are returning the Weekday name of a Hire Date column.

For this MySQL Dayname function demo, we are using Workbench to write a query against the customer table.

SELECT EmpID,
FirstName,
LastName,
Occupation,
YearlyIncome,
Sales,
HireDate,
DAYNAME(HireDate)
FROM `MySQL Tutorial`.customer;

OUTPUT

MySQL DAYNAME Function 4

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