You can use the DAYOFWEEK()
function in MySQL to return the day of the week from a date.
In this context, a return value of 1 corresponds to Sunday, 2 corresponds to Monday, etc.
This article contains examples to demonstrate.
Database Management Systems
You can use the DAYOFWEEK()
function in MySQL to return the day of the week from a date.
In this context, a return value of 1 corresponds to Sunday, 2 corresponds to Monday, etc.
This article contains examples to demonstrate.
You can use the DAYNAME()
function in MySQL to return the weekday name from a date.
By “weekday name”, I mean a value like Monday or Sunday. For example, if you provide a date of 2018-01-07, the DAYNAME()
function will return Sunday.
In MySQL, the DAY()
function is a synonym for the DAYOFMONTH()
function. It’s used to return the day of the month from a date.
In this context the “day of the month” is a value between 1 and 31, or 0 for dates with a zero day part. For example, if you provide a date of 2020-05-03, the DAY()
function will return 3.
You can use the DAYOFMONTH()
function in MySQL to return the day of the month from a date.
By “day of the month”, I mean a value between 1 and 31 (or 0 for dates with a zero day part), as opposed to the day of the week, such as Monday etc.
For example, if you provide a date of 2018-01-07, the DAYOFMONTH()
function will return 7.
This article contains examples of the DATE_FORMAT()
function in MySQL.
The DATE_FORMAT()
function allows you to return a date in a specified format. For example, you can use it to return 2020-06-18 as Thursday, June 2020, or whatever other format you require.
In MySQL, you can use the DATEDIFF()
function to find the difference between two dates. The way it works is, you provide two arguments (one for each date), and DATEDIFF()
will return the number of days between the two dates.
Examples below.
When using MySQL, you can use the DATE()
function to extract the date part from a date or datetime expression.
Here’s how it works.
When returning the current date/time in MySQL, there are a range of functions you can choose from. Most of these are simply synonyms for another function.
However, there are two functions that appear to do the same thing, but are in actual fact, slightly different. The functions I’m referring to are SYSDATE()
and NOW()
.
The MySQL SYSDATE()
function returns the current date and time. The value is returned in ‘YYYY-MM-DD HH:MM:SS’ or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context.
This function is similar to NOW()
but with a subtle difference. SYSDATE()
returns the time at which it executes. NOW()
returns the time at which the statement started executing.
Continue reading