Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/179063-solved-strtotime/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/179063-solved-strtotime/#findComment-944744
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/179063-solved-strtotime/#findComment-944788
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/179063-solved-strtotime/#findComment-944821
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.