Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Mysql Date Arithmetic

Date Arithmetic is used to display the current date, interval in current date and time.

Ads

Mysql Date Arithmetic

     

Date Arithmetic is used to display the current date, interval in current date and time.

Understand with Example

The Tutorial illustrate an example from 'Date Arithmetic' in Mysql. To grasp this example, we  run the select now ( ) query that return you the current date and time.

SYNTAX:-date + INTERVAL expression unit

Query:-

For current date and time

mysql> Select now();

Output:-

+---------------------+
| now() |
+---------------------+
| 2008-12-19 14:34:02 |
+---------------------+
1 row in set (0.02 sec)

Query:-

The Query returns you the 2 days and time before the current time 

For subtracting 2 days from current date.

mysql> select now()- interval 2 day;

Output:-

+-----------------------+
| now()- interval 2 day |
+-----------------------+
| 2008-12-17 14:34:47 |
+-----------------------+
1 row in set (0.02 sec)

Query:-

The Query returns you the 5 minute before the current minute.

For current date+time minus 5 minutes

mysql> select now()- interval 5 minute;

Output:-

+--------------------------+
| now()- interval 5 minute |
+--------------------------+
| 2008-12-19 14:35:13 |
+--------------------------+
1 row in set (0.00 sec)

Query:-

The Query adds 5 days to the current date.

For Adding 5 days from current date.

mysql> select now()+ interval 5 day;

Output:-

+-----------------------+
| now()+ interval 5 day |
+-----------------------+
| 2008-12-24 14:45:06 |
+-----------------------+
1 row in set (0.00 sec)

Advertisements

Share on Google+Share on Google+

Mysql Date Arithmetic

Posted on: December 31, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Mysql Date Arithmetic  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Lalit Mali
January 8, 2013
Thank you.

You solved my problem. Thank you :)

Ads

 

Ads