How to Get the Day from a Date in SQL

To find the day of the week from a given date in SQL, use the DAYNAME() function. This function takes a single argument, which is the date you want to get the day of the week for. For example, if you wanted to get the day of the week for the date 2020-05-01, you would use the following query:

SELECT DAYNAME('2020-05-01');

Examples

Let's look at a few examples of how this function can be used. Suppose you have a table called orders with the following data:

orders
order_date
2020-01-01
2020-02-15
2020-03-31


If you wanted to get the day of the week for each order date, you would use the following query:

SELECT DAYNAME(order_date) FROM orders;

This query would return the results Thursday, Friday, Saturday, and Sunday, respectively.

Additional Info

The DAYNAME() function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database.

Ready to write SQL using AI... for Free? 👇👇