Dates
Moderator: General Moderators
Look into strtotime().
This is better than adding 4 * 60 * 60 seconds, as this takes care of daylight saving time as well (and is just generally cleaner)
Code: Select all
$modified = strototime('+4 hours',$original);Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
In reply to his cross post...blazer21 wrote:PHP v5.0.2
When running the following code date always returns 04:00:00 for the time and not 4 hours past the current time?
Code: Select all
echo $date('m/d/Y h:i:s', strtotime('+4 hours', time()));
Aside that you should change $date to date it worked fine for me.
Consider trying this
Code: Select all
echo date('m/d/Y h:i:s', strtotime('+4 hours'));Code: Select all
echo date('m/d/Y h:i:s', (time()+14400));Funny I can't seem to get strtotime('+4 hours') to work correctly even using your posted code. So, I'm going to use the following.
Code: Select all
echo date('h:i:s', (time()+14400));- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Try this custom function found at http://ca3.php.net/strtotime who have reported strtotime having some problems with php5
Code: Select all
function strtotimefix($strtotime)
{
return time() + (strtotime($strtotime) - strtotime('now'));
}
Last edited by John Cartwright on Wed Jun 22, 2005 4:57 pm, edited 1 time in total.