SQL DAYNAME() Function


The SQL DAYNAME() is a function, and returns the name of the weekday of a given input date value.

The SQL DAYNAME() function returns a String indicating the specified day (Sunday, ..., Saturday) of the week.

The SQL DAYNAME() function is supports only date or datetime based table columns or fields.

It can be used in SELECT statement as well in where clause.


Search Keys

  • sql datename function
  • sql server day of week
  • sql server weekday
  • sql day of week
  • sql day
  • sql weekday
  • day sql
  • day of week sql
  • weekday sql
  • day of week sql server
  • sql server datename
  • sql day of year
  • sql day of the week
  • sql server day of week name
  • sql server weekday function
  • sql datepart weekday
  • sql server get weekday
  • sql server day of week number
  • get day from date sql server
  • sql server date day of week

SQL DAYNAME() Syntax

The below syntax is used to extract specified dayname of the week from given a input date value.

For SQL SERVER / MY SQL


SELECT DAYNAME('valid_date_value');

For MS Access


SELECT WEEKDAYNAME(valid_integer_number);


SQL DAYNAME() Example - Using Expression Or Formula

The following SQL SELECT statement will extract the day of week value from a given input date value. We use now() function to get the input date value.

For SQL SERVER / MY SQL


SELECT 
NOW() AS 'Current Date and Time', 
DAYNAME(NOW()) AS 'Day Name';

For MS Access


SELECT 
NOW() AS 'Current Date and Time', 
WEEKDAYNAME(WEEKDAY(NOW())) AS 'Day Name';

Note: the WEEKDAY() function returns a integer (between 1 and 7) containing a whole number representing the day of the week.

The result of above query is:

Current Date and Time Day Name
16-06-2013 15:48:52 Sunday

Sample Database Table - BookOrder

BookID BookName OrderDate
1 Beginning SQL Queries 15-03-2005 01:15:26
2 The SQL Programming Language 15-03-2000 03:13:02
3 Advanced SQL Programming 17-10-2008 09:20:48
4 A Visual Introduction To Sql 13-08-1998 01:58:25
5 MySql Database Internals 22-03-1998 04:30:13
6 MySql for professionals 15-10-2004 09:32:33
7 SQL Server Data Transformation Services 14-07-1997 08:21:28
8 SQL Programming & Database Design 16-03-1997 05:30:51
9 PowerShell for SQL Server Essentials 21-03-2009 20:39:37
10 SQL Functions Reference 12-01-1998 13:18:17
11 Programming With MySQL 18-04-2001 18:43:59
12 Mastering Oracle SQL 18-06-2008 02:25:30

SQL DAYNAME() Example - With Table Column

The following SQL SELECT statement display the column "OrderDate", from the "BookOrder" table. The DAYNAME() function will extract the dayname of week from the column "OrderDate" and we will stored that value to a new column called "Day Name From OrderDate".

For SQL SERVER / MY SQL


SELECT OrderDate, 
DAYNAME(OrderDate) As 'Day Name From OrderDate'
FROM BookOrder;

For MS Access


SELECT OrderDate, 
WEEKDAYNAME(WEEKDAY(OrderDate)-1) AS 'Day Name From OrderDate'
FROM BookOrder;

The result of above query is:

OrderDate Day Name From OrderDate
15-03-2005 01:15:26 Tuesday
15-03-2000 03:13:02 Wednesday
17-10-2008 09:20:48 Friday
13-08-1998 01:58:25 Thursday
22-03-1998 04:30:13 Sunday
15-10-2004 09:32:33 Friday
14-07-1997 08:21:28 Monday
16-03-1997 05:30:51 Sunday
21-03-2009 20:39:37 Saturday
12-01-1998 13:18:17 Monday
18-04-2001 18:43:59 Wednesday
18-06-2008 02:25:30 Wednesday

Search Keys

  • datepart
  • sql server date functions
  • sql datepart
  • sql server datepart
  • sql server getdate
  • sql server current date
  • sql get date
  • sql getdate format
  • sql get date from datetime
  • getdate format sql
  • sql server date time functions
  • sql date query
  • date functions in sql
  • sql server datepart example
  • sql getdate now
  • sql select getdate
  • format getdate sql server
  • ms sql datepart example
  • sql server current date function
  • convert date getdate