Page 1 of 1
Convert Date Syntax
Posted: Tue Aug 31, 2010 5:08 pm
by neesley
My syntax is off. Any help?
Code: Select all
$ins = "INSERT INTO schedule
VALUES (ID, 'date(Y-m-d,strtotime('$_POST[date]'))','$_POST[jakes]','$_POST[gin]','$_POST[wagon]','$_POST[stumble]','$_POST[hatch]','$_POST[step]','$_POST[sheets]')";
Thanks much.
Re: Convert Date Syntax
Posted: Tue Aug 31, 2010 5:40 pm
by Gargoyle
you can't put PHP functions into a mysql query.
Re: Convert Date Syntax
Posted: Tue Aug 31, 2010 5:43 pm
by neesley
Indeed. Just figured that out.
I'm trying this instead, but still getting the wrong reformatting.
Code: Select all
$timestamp = strtotime("$_POST[date]");
$newdate = date("Y-m-d", $timestamp);
echo $_POST[date];
echo $newdate;
The echos are just for testing. However when fed "09-03-2010" it returns "2014-08-31". My understanding was that strtotime could figure out most date formats.
Re: Convert Date Syntax
Posted: Tue Aug 31, 2010 5:59 pm
by Gargoyle
don't use quotes around the POST variable. other than that, strtotime should be able to handle 09-03-2010
Re: Convert Date Syntax
Posted: Tue Aug 31, 2010 6:13 pm
by neesley
Thanks for the help Gargoyle. Unfortunately, the script is still spitting out an incorrect date. I'll keep trying though! Thanks.
Re: Convert Date Syntax
Posted: Tue Aug 31, 2010 6:19 pm
by neesley
Just curious--would this have anything to do with my date field-type being DATETIME instead of TIMESTAMP?
Re: Convert Date Syntax
Posted: Wed Sep 01, 2010 2:12 pm
by neesley
The type of data field didn't matter of course.
But for those keeping score at home, strtotime() will not parse out a date format such as m-d-Y, i.e. 08-10-2010.
Re: Convert Date Syntax
Posted: Wed Sep 01, 2010 6:19 pm
by Gargoyle
But for those keeping score at home, strtotime() will not parse out a date format such as m-d-Y, i.e. 08-10-2010.
works perfectly for me.
Re: Convert Date Syntax
Posted: Wed Sep 01, 2010 7:46 pm
by neesley
Really!? I'm jealous. I just couldn't get it to accept that format. It will parse a date such as July 3rd, 2010, but not the format I was originally giving it. I changed it to Y-m-d...
I'll bet dollars to donuts that I'm coding something incorrectly, but at least I got it semi-working for the moment. Thanks for the heads up.