Get the day, month and year date components : DAYOFMONTH « Date Time « SQL / MySQL






Get the day, month and year date components

    
mysql>
mysql> CREATE TABLE IF NOT EXISTS labor_day
    -> (
    ->   id     INT     AUTO_INCREMENT PRIMARY KEY,
    ->   date   DATETIME NOT NULL
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO labor_day (date) VALUES ("2005-09-05 12:45:30");
Query OK, 1 row affected (0.00 sec)

mysql>
mysql>
mysql> SELECT DAYOFMONTH(date), MONTHNAME(date),YEAR(date)
    -> FROM labor_day;
+------------------+-----------------+------------+
| DAYOFMONTH(date) | MONTHNAME(date) | YEAR(date) |
+------------------+-----------------+------------+
|                5 | September       |       2005 |
+------------------+-----------------+------------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql> # delete this sample table
mysql> DROP TABLE IF EXISTS labor_day;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
  








Related examples in the same category

1.MySQL has other functions for returning just a part of a date: MONTH() and DAYOFMONTH():