Home Sql Sqldate Mysql Date Format codes
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Mysql Date Format codes

Advertisement
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

     

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)
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 3, 2006

Related Tutorials

Ask Questions?    Discuss: Mysql Date Format codes  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
binita
August 14, 2014
mysql

hello
DMCA.com