Mysql Date Format codes

The Tutorial illustrate an example from 'Mysql date format'. In this example we let you know ,how to display the current date and time in the system.

Mysql Date Format codes

Mysql Date Format codes

     

The Tutorial illustrate an example from 'Mysql date format'. In this example we let you know ,how to display the current date and time in the system. The now ( ) as Date is used to display the current date, month, year and time in (hh:mm:sec).

Query:-

mysql> select now() as Date;

Output:-

+---------------------+
| Date |
+---------------------+
| 2008-12-20 11:24:28 |
+---------------------+
1 row in set (0.00 sec)

Query:-

The given Query return the current date, month and year. 

The syntax (now( ),'%e-%m-%y')  return you the date format in dd-mm-yy.

mysql> select date_format(now(),'%e-%m-%y')as Date;

Output:-

+----------+
| Date |
+----------+
| 20-12-08 |
+----------+
1 row in set (0.00 sec)

Query:-

The date_format(now( ),'%W') return you the week of the day.

mysql> select date_format(now(),'%W')as Day;

Output:-

+----------+
| Day |
+----------+
| Saturday |
+----------+
1 row in set (0.00 sec)

Query:-

The below Query (now( ),'%w') return the weekday number . 

mysql> select date_format(now(),'%w')as DayofWeek;

Output:-

+-----------+
| DayofWeek |
+-----------+
| 6 |
+-----------+
1 row in set (0.00 sec)

Query:-

The below Query format(now(),'%e') return you the day of the month.

mysql> select date_format(now(),'%e')as Date;

Output:-

+------+
| Date |
+------+
| 20 |
+------+
1 row in set (0.00 sec)

Query:-

The given below Query (now( ),'%M') show you the month of the year.

mysql> select date_format(now(),'%M')as Month;

Output:-

+----------+
| Month |
+----------+
| December |
+----------+
1 row in set (0.00 sec)

Query:-

The date_format(now( ),'%m') return you the month number of the year.

mysql> select date_format(now(),'%m')as Month;

Output:-

+-------+
| Month |
+-------+
| 12 |
+-------+
1 row in set (0.00 sec)

Query:-

The date_format(now( ),'%W %e%M%Y') return you the current week, day, month and year.

mysql> select date_format(now(),'%W %e %M %Y')as Date;

Output:-

+---------------------------+
| Date |
+---------------------------+
| Saturday 20 December 2008 |
+---------------------------+
1 row in set (0.00 sec)