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
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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Alright, after digging around, I've found it has to do with this javascript time selector I had that inputs the data into the text box. Somehow it messes with it so it doesn't believe that it is a string when it's being input.

Link to comment
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.