PHP - Short hand if statement with a date format with weird output.
Posted
by McNabbToSkins
on Stack Overflow
See other posts from Stack Overflow
or by McNabbToSkins
Published on 2010-04-29T14:01:53Z
Indexed on
2010/04/29
14:07 UTC
Read the original article
Hit count: 290
php
I am using a short hand notation of an if statement to format a field. If the field is an empty string I leave it as an empty string, if not then I am trying to format it to a proper datetime format so it can be inserted into a mysql db. here is my php code
$date = ($date == '') ? date("Y-m-d", strtotime($date)) : $date;
for some reason when the $date string is not empty it is returning it int he format 'm/d/Y' example: 04/01/2010
When I pull the code out of the shorthand if
$date = date("Y-m-d", strtotime($date));
print($date);
it is formatted correctly like this 'Y-m-d' or 2010-04-01. Does anyone know why this happens? Thanks
© Stack Overflow or respective owner