Adding days to date field

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 1, 2009   (RSS)

Re: [eduran582] Adding days to date field

By Dave - August 1, 2009

Hi Eric,

In both MySQL and in the viewers dates are in this format:
2009-07-05 21:05:38

You can convert them to epoch time (seconds since 1970) like this:
$time = strtotime( $myRecord['myDateField'] );

You can add a day to like this:
$time += (60*60*24);

And then convert it back to text like this (see php.net/date for formatting codes):
echo date("D, M jS, Y g:i:s a", $time);

So that's how you do it in PHP. If you're writing a where query for MySQL you can use some MySQL functions though. Here's some examples:

'where' => "publishDate >= NOW()",
'where' => "createdDate >= (NOW() - INTERVAL 1 DAY) ",
'where' => " '2009-07-05 21:05:38' < (myDateField + INTERVAL 1 DAY) ",

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [eduran582] Adding days to date field

By eduran582 - August 1, 2009

Hi Dave,

Once again, right on the money! Just what I needed!

Interactivetools.com has the BEST user support I have ever seen and believe me, I've had my problems with others!

Thanks again for your superior support!

Eric