JustinK101 Posted October 27, 2008 Share Posted October 27, 2008 I need the following: Generate a UTC date and time stamp from now() to (now() - 7) days exactly. So basically two values. How can I do this? Quote Link to comment Share on other sites More sharing options...
corbin Posted October 27, 2008 Share Posted October 27, 2008 time() time()-60*60*24*7 Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted October 27, 2008 Share Posted October 27, 2008 time() returns the current timestamp in GMT (which is the same as UTC, right?) So here are the two values you want: $now = time(); $seven_days_ago = $now - 60*60*24*7; 60*60*24*7 is the number of seconds in 7 days (60 seconds in a minute, 60 minutes in an hour, 24 hours in a day, and 7 days.) Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted October 27, 2008 Author Share Posted October 27, 2008 Corbin: Close, but that is a EPOCH. Those returned: 1225082910 AND 1224478110 The values I need, are going to be feed into MySQL so they need to be in the format of: '2008-10-26 9:49:40' Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted October 27, 2008 Share Posted October 27, 2008 date() will format a timestamp into a string for you. It looks like you want something like this: $date = date('Y-m-d H:i:s', $timestamp); Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted October 27, 2008 Author Share Posted October 27, 2008 Something is very wrong here: echo date('Y-m-d H:i:s', time()); Returns: 2008-10-27 00:24:21 This is not right, UTC time should be 2008-10-27 05:24:21. Any ideas? Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted October 27, 2008 Share Posted October 27, 2008 Something is very wrong here: echo date('Y-m-d H:i:s', time()); Returns: 2008-10-27 00:24:21 This is not right, UTC time should be 2008-10-27 05:24:21. Any ideas? havent tried this but it should work... echo date('Y-m-d H:i:s', time() - 18000); Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted October 27, 2008 Author Share Posted October 27, 2008 Is time localized instead of UTC then? Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted October 27, 2008 Share Posted October 27, 2008 Where is your server located? Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted October 27, 2008 Author Share Posted October 27, 2008 That's the point, I need the date/time to be static, meaning wherever the server is, the date/time is always the same. We actually are going to have web servers located on both the west and east coast, both running the same PHP application. Basically every date/time must be stored in UTC in the database. Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted October 27, 2008 Share Posted October 27, 2008 How about gmdate("Y-m-d H:i:s", time()); Since GMT is the same as UTC this will always return the proper UTC time. Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted October 27, 2008 Author Share Posted October 27, 2008 FructOse: Ahh, ok that seems to work. Thanks. Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted October 27, 2008 Share Posted October 27, 2008 So if you wanted the current UTC timestamp and your UTC - 7 days this would be the easy way to do it: echo gmdate("Y-m-d H:i:s", time()); echo gmdate("Y-m-d H:i:s", strtotime("-7 days")); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.