Jump to content

handling date and time


mrjameer

Recommended Posts

hi,

 

 

i have a table in which there are 2 fields

1.id

2.date.

 

values

1  2005-07-28 15:07:52

 

the time is 3:07:52. 

 

here what i want to do is i want to add 8 hours to the above time

(result should be like 2005-07-28 11:07:52 PM).if it exceeds the date just take next day's date.any of your help will be surely appreciated.

 

thanks

mrjameer

Link to comment
https://forums.phpfreaks.com/topic/49702-handling-date-and-time/
Share on other sites

Follow this link:

http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_date-add

 

Then scroll down until you see:

As of MySQL 3.23, date arithmetic also can be performed using INTERVAL together with the + or - operator:

date + INTERVAL expr unit
date - INTERVAL expr unit

 

Following is a list of date manipulations you can perform right in SQL without using any PHP code.

here what i want to do is i want to add 8 hours to the above time

(result should be like 2005-07-28 11:07:52 PM).if it exceeds the date just take next day's date.any of your help will be surely appreciated.

 

Or, an example of how to let MySQL do the work for you (you will have to do this if your date falls outside of the UNIX timestamp range):

SELECT DATE(date + INTERVAL 8 HOUR) FROM myTable;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.