Home Sql Sqldate Mysql Date Arithmetic



Mysql Date Arithmetic
Posted on: December 31, 2008 at 12:00 AM
Date Arithmetic is used to display the current date, interval in current date and time.

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)

Related Tags for Mysql Date Arithmetic:
cdatetimeseddisplayintarithmetictointervaleitspluseimcurrentinmntplayispmesspatisimeandarrvvassrirenthdispplndo


More Tutorials from this section

Ask Questions?    Discuss: Mysql Date Arithmetic  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.