Page 1 of 1

date() and/or strtotime() not working [solved]

Posted: Thu Jan 19, 2006 10:54 am
by imstupid
hello everybody:
Here's the situation. I've created this trouble-ticket posting system, where a user submits a problem to our glorious hr department, and while doing so, a "time posted" variable is submitted using this code:

Code: Select all

<?PHP
$ue_today = mktime(date("G"), date("i"), date("s"), date("m"), date("d"), date("Y"));
$timeposted = date ("Y-m-d G:i:s", $ue_today);	
?>
into a datetime field. I use the variable $timeposted as a unique identifier, so our hr guy and update each ticket from "unanswered" to "in progress" to "resolved" blah blah. I'm sure you get the idea. Anyway, the problem is, the update query isn't working, and I think it has to do with the way I'm handling the date or strtotime part. The date (which I modified to make it a little more readable) originally comes over in this format: Jan 18, 4:13:34 pm to this php code:

Code: Select all

<?PHP
$timeposted = $_POST['timeposted'] ;

//code here, etc..

$timeposted = date ("Y-m-d G:i:s",  strtotime($timeposted));	

// update query here
?>
This has got to be wrong somewhere, because it echos -1, which would mean the string is bad according to the manual, right? I've also tried screwing around with it, and

Code: Select all

$timeposted = date("Y-m-d g:i:s", $timeposted) ;
echos the old 1969-12-31 6:00:00 treatment. It's probably staring me in the face, but any help or advice would be helpful.

hope all is well. holy crap, sorry this is so long.

Posted: Thu Jan 19, 2006 11:21 am
by sheila
You don't need all this

Code: Select all

$ue_today = mktime(date("G"), date("i"), date("s"), date("m"), date("d"), date("Y"));
$timeposted = date ("Y-m-d G:i:s", $ue_today);
Just do this way

Code: Select all

$timeposted = date ("Y-m-d G:i:s", localtime());
But an easier way, since this being inserted into a datetime field of a database, would be to let the database handle it.
Set the field to NOW() (instead of $timeposted) and it should work just fine.

Sheila

Posted: Thu Jan 19, 2006 11:23 am
by RobertGonzalez
Is your input field in the form actually named 'timeposted'? What it looks like is $_POST['timeposted'] is sending either null data or 0. That is why your date is showing as 1969-12-31.

Also, have you cleared your cache and echo'ed out the value of $_POST['timeposted']?

Posted: Thu Jan 19, 2006 3:11 pm
by imstupid
Thanks for the help - it was actually my fault on an earlier page (I was using strtotime again, even though I used it on the previous page). Thanks anyway, appreciate the tips too.