Default datetime format in mySQL
Posted
by
Davuz
on Stack Overflow
See other posts from Stack Overflow
or by Davuz
Published on 2012-06-04T10:26:46Z
Indexed on
2012/06/04
10:40 UTC
Read the original article
Hit count: 182
I'm coding to search data by compare datetime. In web form, user input value '2012-06-04' store in $_REQUEST['dateSearch']. I create datetime object from that:
$dateObj = date_create_from_format("Y-m-d",$_REQUEST['dateSearch']);
$dateParam = $dateObj->format("Y-m");
Then I use $dateParam in sql query to find data
$sql = "
SELECT *
FROM `temp` as `t`
WHERE `t`.`date` LIKE '$dateParam%'
";
Everything is ok, but I'm not sure mySQL alway use only one datetime format "Y-m-d H:i:s".
At here, $dateParam = $dateObj->format("Y-m");
I set default format is "Y-m". Is the default format never change? I don't want hard set format "Y-m-d H:i:s" in code, instead of, I think get format string from system to use is better. How do I get default datetime format string from mySQL???
© Stack Overflow or respective owner