SQL DAY() Function


The SQL DAY() is a function, and return or extract the day value portion or day of the month (a whole integer number from 1 to 31) of a given input date value.

The SQL DAY() 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 day function
  • sql today
  • sql day of week
  • today sql server
  • sql server days
  • sql day
  • sql last day of month
  • sql date today
  • day of week sql
  • sql server date today
  • sql server day function
  • sql day of month
  • last day of month sql
  • sql days between dates
  • sql day of the week
  • get day from date sql
  • sql where date today
  • sql query today
  • sql today function
  • sql current day
  • days between sql

SQL DAY() Syntax

The below syntax is used to get day value portion from a given input date value using DAY() function.

For SQL SERVER / MY SQL / MS ACCESS


SELECT DAY('valid_date_value');

The below syntax is used to get day of the month (a integer number from 1 to 31) value from a given table date or datetime column using DAY() function.

For MS ACCESS / SQL SERVER / MY SQL


SELECT DAY(date_column_name1) FROM table_name;


SQL DAY() Example - Using Expression Or Formula

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


SELECT 
NOW() AS 'Current Date and Time', 
DAY(NOW()) AS 'Day Value';

The result of above query is:

Current Date and Time Day Value
24-08-2012 19:37:30 24

Sample Database Table - BookOrder

BookID BookName OrderDate Qty DeliveryDate
1 SQL: The Complete Reference 13-05-2000 10:29:29 10 27-05-2000 09:54:59
2 The Gurus Guide To SQL Server 17-06-2002 23:05:18 4 21-07-2002 07:48:21
3 Troubleshooting Oracle 19-07-2007 13:59:49 13 28-07-2007 06:53:51
4 MySql for professionals 24-10-2000 19:31:33 2 27-10-2000 23:31:55
5 Oracle Database Internals 23-03-1997 16:09:51 7 26-03-1997 22:11:18
6 Oracle Concurrency 16-08-2007 05:27:10 8 25-09-2007 07:47:34
7 SQL Pocket Guide 16-04-2004 11:53:44 3 28-05-2004 18:59:39
8 Microsoft SQL Server 2012 22-06-2010 08:16:33 2 26-07-2010 02:46:31
9 SQL Server: The Complete Reference 20-07-2001 09:18:13 3 28-07-2001 07:33:23
10 Learing Sql Server T-Sql 13-03-2002 11:31:05 19 17-04-2002 13:02:03
11 Securing Oracle 21-08-2001 03:14:01 7 28-08-2001 17:27:13
12 Postgresql Official Documentation 15-05-1995 17:10:42 7 22-05-1995 06:26:09

SQL DAY() Example - With Table Column

The following SQL SELECT statement display the column "OrderDate" and "DeliveryDate", from the "BookOrder" table. The DAY() function will extract the day of the month value(a whole integer number from 1 to 31) from the column "OrderDate" and we will stored that value to a new column called "Order Day" and "Delivery Day".


SELECT 
OrderDate, DAY(OrderDate) As 'Order Day', 
DeliveryDate, DAY(DeliveryDate) As 'Delivery Day' 
FROM BookOrder;

The result of above query is:

OrderDate Order Day DeliveryDate Delivery Day
13-05-2000 10:29:29 13 27-05-2000 09:54:59 27
17-06-2002 23:05:18 17 21-07-2002 07:48:21 21
19-07-2007 13:59:49 19 28-07-2007 06:53:51 28
24-10-2000 19:31:33 24 27-10-2000 23:31:55 27
23-03-1997 16:09:51 23 26-03-1997 22:11:18 26
16-08-2007 05:27:10 16 25-09-2007 07:47:34 25
16-04-2004 11:53:44 16 28-05-2004 18:59:39 28
22-06-2010 08:16:33 22 26-07-2010 02:46:31 26
20-07-2001 09:18:13 20 28-07-2001 07:33:23 28
13-03-2002 11:31:05 13 17-04-2002 13:02:03 17
21-08-2001 03:14:01 21 28-08-2001 17:27:13 28
15-05-1995 17:10:42 15 22-05-1995 06:26:09 22

Search Keys

  • add days to date sql
  • get day from date sql server
  • current day sql
  • sql server date functions
  • sql date functions
  • sql datetime
  • sql date format
  • current date sql
  • sql convert date
  • ms sql date functions
  • mssql current date
  • sql server convert date
  • sql server date time
  • sql system date
  • sql now date
  • sql subtract dates
  • sql server compare dates
  • sql current_date
  • sql date operations
  • sql date example
  • sql date type