SQL MONTH() Function
The SQL MONTH() is a function, and return or extract the month value (a whole integer number from 1 to 12) of a given input date value.
The SQL MONTH() 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 month function
- sql month
- month sql server
- sql server month from date
- sql month from date
- sql get month
- sql date month
- sql year month
- sql current month
- sql where month
- sql getdate month
- select month sql
- sql month and year
- sql server datepart month
- sql month of date
- sql server last month
- sql server current month
- sql day of month
- sql date month year
SQL MONTH() Syntax
The below syntax is used to get month value from a given input date value using MONTH() function.
For SQL SERVER / MY SQL / MS ACCESS
SELECT MONTH('valid_date_value');
The below syntax is used to read month portion (a integer number from 1 to 12) value from a given table column using MONTH() function.
For MS ACCESS / SQL SERVER / MY SQL
SELECT MONTH(date_column_name1) FROM table_name;
SQL MONTH() Example - Using Expression Or Formula
The following SQL SELECT statement will extract 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',
MONTH(NOW()) AS 'Month Value';
The result of above query is:
Current Date and Time |
Month Value |
24-08-2012 19:37:30 |
8 |
Sample Database Table - BookOrder
BookID |
BookName |
OrderDate |
Qty |
DeliveryDate |
1 |
SQL Server 2012 Black Book |
12-05-2009 07:10:20 |
6 |
21-05-2009 08:23:03 |
2 |
Professional MySql |
11-01-2007 02:52:12 |
18 |
15-02-2007 20:21:26 |
3 |
Data Analysis Using SQL |
17-08-2009 19:51:55 |
15 |
26-09-2009 07:52:29 |
4 |
PHP And MySQL Bible |
17-09-2001 19:39:05 |
7 |
21-10-2001 14:56:30 |
5 |
Jump Start MySQL |
19-01-2002 19:53:01 |
2 |
23-01-2002 12:08:32 |
6 |
Oracle PL/sql By Example |
19-04-2008 23:43:09 |
14 |
21-04-2008 17:22:54 |
7 |
SQL Pocket Guide |
25-07-1998 22:26:46 |
5 |
28-07-1998 23:29:41 |
8 |
Database Systems Using Oracle |
24-03-2003 13:04:45 |
11 |
27-04-2003 08:16:29 |
9 |
Foundations Of Sql Server 2008 |
16-02-2003 03:57:22 |
12 |
21-03-2003 18:06:59 |
10 |
Professional Oracle |
15-01-1999 11:36:26 |
12 |
26-01-1999 20:23:20 |
11 |
The SQL Programming Language |
21-07-1996 12:44:58 |
13 |
25-07-1996 17:45:59 |
12 |
The Microsoft Data Warehouse |
21-09-2008 23:46:16 |
3 |
26-10-2008 16:04:57 |
SQL MONTH() Example - With Table Column
The following SQL SELECT statement display the column "OrderDate" and "DeliveryDate" from the "BookOrder" table.
The MONTH() function will extract the month value(a whole integer number from 1 to 12) from the column "OrderDate" and
we will stored that value to a new column called "Order Month" and "Delivery Month".
SELECT
OrderDate, MONTH(OrderDate) As 'Order Month',
DeliveryDate, MONTH(DeliveryDate) As 'Delivery Month'
FROM BookOrder;
The result of above query is:
OrderDate |
Order Month |
DeliveryDate |
Delivery Month |
12-05-2009 07:10:20 |
5 |
21-05-2009 08:23:03 |
5 |
11-01-2007 02:52:12 |
1 |
15-02-2007 20:21:26 |
2 |
17-08-2009 19:51:55 |
8 |
26-09-2009 07:52:29 |
9 |
17-09-2001 19:39:05 |
9 |
21-10-2001 14:56:30 |
10 |
19-01-2002 19:53:01 |
1 |
23-01-2002 12:08:32 |
1 |
19-04-2008 23:43:09 |
4 |
21-04-2008 17:22:54 |
4 |
25-07-1998 22:26:46 |
7 |
28-07-1998 23:29:41 |
7 |
24-03-2003 13:04:45 |
3 |
27-04-2003 08:16:29 |
4 |
16-02-2003 03:57:22 |
2 |
21-03-2003 18:06:59 |
3 |
15-01-1999 11:36:26 |
1 |
26-01-1999 20:23:20 |
1 |
21-07-1996 12:44:58 |
7 |
25-07-1996 17:45:59 |
7 |
21-09-2008 23:46:16 |
9 |
26-10-2008 16:04:57 |
10 |