ballhogjoni Posted January 29, 2009 Share Posted January 29, 2009 I can't figure this one out. My is : strtotime(2009-01-29 12:44:12) - time(); and I keep getting random numbers. I get like 539, 408, 670,324, etc... I diagnosed it to the time() it keeps returns random seconds. Any ideas why this is happening? Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/ Share on other sites More sharing options...
dennismonsewicz Posted January 29, 2009 Share Posted January 29, 2009 try looking at this http://us.php.net/manual/en/function.strtotime.php Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/#findComment-749863 Share on other sites More sharing options...
printf Posted January 29, 2009 Share Posted January 29, 2009 time(); // returns the number of seconds since Jan 1, 1970 (Uinx Epoch), it always changes! Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/#findComment-749865 Share on other sites More sharing options...
ballhogjoni Posted January 29, 2009 Author Share Posted January 29, 2009 time(); // returns the number of seconds since Jan 1, 1970 (Uinx Epoch), it always changes! LOL good point. I guess I should have explained myself a little better. I am taking the value of this (strtotime(2009-01-29 12:44:12) - time() equation and creating a countdown from the value. this will give the seconds I need to create that countdown. The problem is that if I refresh the page it will give me a random number of seconds (not what i'm expecting). Lets say the equation gave me 600 seconds the first time I go to the page and then I refresh the page one second later and I get 300 seconds as a value from the equation. You see the problem is that the equation is giving a random number of seconds. I was able to pinpoint the issue to the time(). Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/#findComment-749870 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 little example for you. <?php //1 month $Time=strtotime("2009-01-29 12:44:12 -1 MONTH"); echo" ".date("M/d/y,h:i:s",$Time)." <br>"; // 1 week. $Time=strtotime("2009-01-29 12:44:12 -1 WEEK"); echo" ".date("M/d/y,h:i:s",$Time)."<br> "; // 1 year. $Time=strtotime("2009-01-29 12:44:12 -1 YEAR"); echo" ".date("M/d/y,h:i:s",$Time)."<br> "; // 1 week 1 day. $Time=strtotime("2009-01-29 12:44:12 -1 WEEK 1 DAY"); echo" ".date("M/d/y,h:i:s",$Time)."<br> "; // 1 week 1 day= 3 hours 2 secounds $Time=strtotime("2009-01-29 12:44:12 -2 WEEK 1 DAY 3 HOURS 2 SECONDS"); echo" ".date("M/d/y,h:i:s",$Time)."<br> "; ?> what is it your trying to do please, so we no. Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/#findComment-749893 Share on other sites More sharing options...
ballhogjoni Posted January 29, 2009 Author Share Posted January 29, 2009 Why does time() give you a random number (not incremental) when you refresh the page. I thought it was supposed to give the number of seconds since 1970. Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/#findComment-749977 Share on other sites More sharing options...
PFMaBiSmAd Posted January 29, 2009 Share Posted January 29, 2009 It should be displaying an increasing number approximately in the ball park of 123326xxxx, depending on what your local server's time is. Either your php installation is having a problem, or your server's time is being dynamically changed or your code that is using the result of the time() value has a bug in it. Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/#findComment-750011 Share on other sites More sharing options...
ballhogjoni Posted January 29, 2009 Author Share Posted January 29, 2009 What if I jsut use date("U") Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/#findComment-750048 Share on other sites More sharing options...
DarkWater Posted January 29, 2009 Share Posted January 29, 2009 Umm, I hope you have quotation marks around the date/time in this: strtotime(2009-01-29 12:44:12) - time() You do, right? Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/#findComment-750087 Share on other sites More sharing options...
ballhogjoni Posted January 29, 2009 Author Share Posted January 29, 2009 Umm, I hope you have quotation marks around the date/time in this: strtotime(2009-01-29 12:44:12) - time() You do, right? no, its actually a variable. just put a date in the strtotime for example Link to comment https://forums.phpfreaks.com/topic/143005-crazy-issue-with-time/#findComment-750107 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.