richiec Posted October 26, 2009 Share Posted October 26, 2009 Hey all so im building this one page on my site and it requires people to put in a time and then it will save the time and also a time 36 hours after the time which is put in. So basically a time and then 36 hours after that time but i keep traveling back in time lol I have this in my code: //example: October 26th, 2009, 12:00 pm $updatetime = $_POST["updatebosstime"]; //date and time 36 hours after the example $ts = strtotime("$updatetime") + (60 * 60 * 36); $nt = date("F jS, Y, g:i a ", $ts); however its just coming up with January 2nd, 1970, 6:59 am whenever it gets updated, any ideas on how to fix it to display correctly? Quote Link to comment https://forums.phpfreaks.com/topic/179063-solved-strtotime/ Share on other sites More sharing options...
JonnoTheDev Posted October 26, 2009 Share Posted October 26, 2009 $future = strtotime("+36 hour", strtotime($updatetime)); print date('d-m-Y H:i:s', $future); Quote Link to comment https://forums.phpfreaks.com/topic/179063-solved-strtotime/#findComment-944737 Share on other sites More sharing options...
richiec Posted October 26, 2009 Author Share Posted October 26, 2009 still does the same thing Quote Link to comment https://forums.phpfreaks.com/topic/179063-solved-strtotime/#findComment-944741 Share on other sites More sharing options...
JonnoTheDev Posted October 26, 2009 Share Posted October 26, 2009 Then check your syntax. The following works perfectly: <?php $future = strtotime("+36 hour", strtotime("October 26th, 2009, 12:00pm")); print date('d-m-Y H:i:s', $future); ?> I notice you are enclosing varaibles in quotes as function parameters i.e. strtotime("$updatetime") This is bad syntax. Also validate the data that comes from your form. Is it a valid date string? print $_POST['updatebosstime']; If no valid date is contained within the post array the unix epoch date is used 01-01-1970 Quote Link to comment https://forums.phpfreaks.com/topic/179063-solved-strtotime/#findComment-944744 Share on other sites More sharing options...
richiec Posted October 26, 2009 Author Share Posted October 26, 2009 I just tried it on a fresh page with nothing else on it and this is all that was printed back: 02-01-1970 06:59:59 <-- using exactly what you just posted October 26th, 2009, 12:27 pm <-- print $_POST['updatebosstime']; Quote Link to comment https://forums.phpfreaks.com/topic/179063-solved-strtotime/#findComment-944750 Share on other sites More sharing options...
JonnoTheDev Posted October 26, 2009 Share Posted October 26, 2009 This exact code produces an invalid date on your server? <?php $future = strtotime("+36 hour", strtotime("October 26th, 2009, 12:00pm")); print date('d-m-Y H:i:s', $future); ?> If so check the timezone environment variables on your php installation. What version are you running. You may need to use a US English date format. Read the description of the strtotime function http://uk.php.net/strtotime Quote Link to comment https://forums.phpfreaks.com/topic/179063-solved-strtotime/#findComment-944788 Share on other sites More sharing options...
richiec Posted October 26, 2009 Author Share Posted October 26, 2009 Well i have got it working now, i just broke it all down and changed a few things around. This is how i got it working, its not great but it works lol: First of all i split the date and time from the form so one is date the other is time, i also changed the submitted format around to now be submitted as 10-26-09 and 1:35 PM $updatebosstime = $_REQUEST['updatebosstime']; $updatebossdate = $_REQUEST['updatebossdate']; $temp = explode("-",$updatebossdate); $newdate = $temp[2] . "-" . $temp[0] . "-" . $temp[1]; $ts = strtotime("$newdate $updatebosstime") + (60 * 60 * 36); $nt = date("F jS, Y, g:i a", $ts); like i said, its not great and its just temp until i figure out how to get it working the shorter way instead of being so messy but it works for now. Thanks for the help, now i just need to figure out how to work out how long is left until the 36 hours a count down timer kinda thing lol ~Rich Quote Link to comment https://forums.phpfreaks.com/topic/179063-solved-strtotime/#findComment-944821 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.