Jump to content

[SOLVED] date and mktime


richiec

Recommended Posts

Hey guys im having a bit of an issue.. Ill try to explain it best way i can with what it is i am trying to do..

 

Ok first of all in html i have a select option with a drop down menu with a bunch of names.. Under that i have 2 text boxes for date and time (the user imputs the date and time something happend)

 

Now depending on the drop down select name clicking submit will add a set number of hours to the date and time the user submited.

 

Lets say the user imputs todays date 08-22-08 and the time 12:34pm and lets say they select a name which adds 18 hours onto that time..

 

if ($_REQUEST["Submit"] != NULL){
$name = $_REQUEST["name"];
$date = $_REQUEST["date"];
$time = $_REQUEST["time"];

if ($name == "some name"){
$add = "18"; // hours to add to the date and time
$name = "some name";
}

 

Now the output i would want, would be something like.. "$name will happen again on 08-23-08 at 6:34am" (adding 18 hours to the time and date they imputed)

 

any idea how i would do that could i get an example?

 

Thanks alot,

 

Rich

Link to comment
https://forums.phpfreaks.com/topic/120888-solved-date-and-mktime/
Share on other sites

Ah I know why.  strtotime considers the first number to be the year when using "-" as a separator so it's parsing it as "y-m-d" instead of "m-d-y" You can fix this by changing your form to use "/" instead of "-" like "m/d/y" or by reordering the string using substr or maybe using explode like

 

$date = "08-22-08";

$temp = explode("-",$date);

$newdate = $temp[2] . "-" . $temp[0] . "-" . $temp[1];

 

then strtotime($newdate) etc...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.