I am having a problem converting a date to be used to query my database. I am passing the date to my PHP script in this format: mm/dd/yyy and in order to query my databases date field it needs to be in this format: yyyy-mm-dd How can I do this with PHP?
try something as basic as $bits = explode('/',$date); var_dump($bits); //just so you can see what the explode did. delete once you're up and running. $dateymd = $bits[2].'-'.$bits[0].'-'.$bits[1]; var_dump($dateymd); //just so you can see the NEW variable. delete once you're up and running. PHP: As a non-american I just can't fathom this whole month-day-year thing. Seems more logical to do small units to big units (british dates) or big units to small (data) - but that's just me
The date() function is for this: <?php $date = date("m/d/y", "1265506687"); $new_date_format = date("y-m-d", $date); echo $new_date_format; ?> PHP:
The OP could use strtotime() for the conversion into timestamp. <?php $date = strtotime("02/28/2010"); $new_date_format = date("y-m-d", $date); echo $new_date_format; ?> PHP:
it amazes me sometimes how ppls DONT use google. google "php date" and it would have taken u 2 minutes to find I have the php date page in my favs as i am working on a booking management script. try to always have your date in your script, in the same format as a mysql timestamp, so u can use it in querys with ease
I think I may have an error somewhere else because that is what I am doing but it is not working! Will report back with my findings!