86Stang Posted April 21, 2008 Share Posted April 21, 2008 How can I get this date to return with a -2 hours on it? In other words, the server is two hours ahead of me and I would like the timestamp to save at - 2 hours instead of the servers current time. $updated = date("Y-m-d h:i:s"); Link to comment https://forums.phpfreaks.com/topic/102102-date-modification/ Share on other sites More sharing options...
Barand Posted April 21, 2008 Share Posted April 21, 2008 <?php $updated = date("Y-m-d h:i:s", strtotime('-2 hours')); echo $updated; ?> Or, if you are writing to a database, you can INSERT INTO mytable (updated) VALUES (NOW() - INTERVAL 2 HOUR) Link to comment https://forums.phpfreaks.com/topic/102102-date-modification/#findComment-522674 Share on other sites More sharing options...
86Stang Posted April 21, 2008 Author Share Posted April 21, 2008 I'm always astounded at how simple the answers to my questions seem. That probably doesn't say that much for my coding skills but it is what it is I guess. I've noticed that most of my problems are with syntax/structuring. For example, I tried your solution Barand but without the single quotes around the "-2 hours". Is there a site that anyone can recommend where I can learn how to properly structure this stuff? Link to comment https://forums.phpfreaks.com/topic/102102-date-modification/#findComment-522824 Share on other sites More sharing options...
soycharliente Posted April 21, 2008 Share Posted April 21, 2008 Always read the manual first. I usually find answers to my questions (and yours) right there. Link to comment https://forums.phpfreaks.com/topic/102102-date-modification/#findComment-522828 Share on other sites More sharing options...
PFMaBiSmAd Posted April 21, 2008 Share Posted April 21, 2008 It is not about coding skills. It is about research (and perhaps reading.) The php manual (http://www.php.net/docs.php - I recommend the down-loadable CHM version because the index and search functions let you find most of what you are looking for) contains all the basic information that was used for writing books, tutorials, and most of the basic answers in a forum... In the case of the strtotime() function, the syntax prototype in the manual indicates that the first parameter is a string (meaning it needs to be quoted and Barand would not have posted it that way if it did not need to be that way) - Description int strtotime ( string $time [, int $now] ) Link to comment https://forums.phpfreaks.com/topic/102102-date-modification/#findComment-522834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.