hi..i'm writing a program to load a csv file to mysql. in that csv file there is a date field which contains value of the form : dd/mm/yy H:i,that is 24/01/13 14:58. how can i convert that to mysql date format yyyy-mm-dd. no time is needed.. i tried different functions like:
1) strtotime
2)Datetime:createFromFormat
3)date_format
,but nothing helped.maybe i used them in a wrong way. can anyone please help me to do this. Thanks in advance.
how to convert string of format dd/mm/yy to mysql date form
Moderator: General Moderators
Re: how to convert string of format dd/mm/yy to mysql date f
The problem here is the two-character year. 24/01/2013 works fine. 24/01/13 not so much. Best bet at this point is probably to tokenize the string, add the leading '20' and rearrange the tokens. Alternately, you could do a regex replace to insert the '20' after the second slash and then parse with DateTime or strtotime.
Re: how to convert string of format dd/mm/yy to mysql date f
Code: Select all
date_default_timezone_set("Europe/Kiev");
$str = "24/01/13 14:58";
var_dump(DateTime::createFromFormat('d/m/y H:i', $str)->format('Y-m-d')); // string(10) "2013-01-24"
Re: how to convert string of format dd/mm/yy to mysql date f
@Weirdan: thanks friend that worked well...
(y)
@celauran: thanks friend for helping me..
@celauran: thanks friend for helping me..