Jump to content

strtotime() quick problem


Ty44ler

Recommended Posts

$time = "8:00 AM";
$time2 = $data['arrived'.$i]; //echo's out to be "8:00 AM"

		if (($timestamp = strtotime($time)) === false) {
		echo "The string ($time) is bogus";
		} else {
			echo date('h:i A', $timestamp);
				}

 

This function works when I put in $time but doesn't work when I put in $time2.

 

$time2 echo's out to be "8:00 AM"

 

$data['arrived'.$i] comes from a form that the user selects the time form.

 

Why does $time work, but $time2 doesn't? They echo out the same thing.

Link to comment
https://forums.phpfreaks.com/topic/200802-strtotime-quick-problem/
Share on other sites

I'm trying to get a time (8:00 AM) to convert to military time (0800). It doesn't get converted. I noticed my date() function wasn't outputting the right format, but it still didn't work nonetheless.

 

Here's a more basic code of mine:

 

$time2 = '8:00 AM';
echo date('Hi', strtotime($time2))//time2

outputs 0800

 

$time1 = $_POST['arrived1']; //echo's to be "8:00 AM"
echo date('Hi', strtotime($time1)) //time1

outputs 0000

Take a look at the second reply. It gives the same results and doesn't use i.

 

$i is just a counter.

 

It'll be actually kind of hard to show you the form, that part of the form is generated dynamically through javascript, but still passes the data the same.

Javascript:

<form method="post" action="submitworkorder.php" name="ComplianceForm" >
<input name=\"arrived'+i+'\" type=\'text\' value=\'8:00 pm\'><input type="submit" value="Preview" name="Preview" /></form>

This code is in a for loop that displays it a number of times depending on user input. I cut out most of the stuff that didn't matter. It gets shown through innerHTML javascript.

I had a little revelation...

 

I put in 800 as the value for the formula and it resulted in 1900. This is the same result when I put my variable in there.

 

So, instead of being read as 8:00 AM I believe it is only being read as 800 in the formula (but it clearly echo's out to 8:00 AM). Whyyyyy????? ahhhhh.... :confused: :confused: :confused:

 

oh and by the way, I edited the values for the input to make sure they weren't messing with anything.

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.