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
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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.