angela_john Posted December 14, 2010 Share Posted December 14, 2010 hi i have a old data formate 1/5/2009 i have to change this in YYYY-MM-DD please help me to do this in preg match thanks Quote Link to comment https://forums.phpfreaks.com/topic/221653-help-in-preg-match/ Share on other sites More sharing options...
mikecampbell Posted December 14, 2010 Share Posted December 14, 2010 Use explode: list($month, $day, $year) = explode('/', '1/5/2009'); You may have to pad your month and day with a zero... if (strlen($day)==1) $day = '0'.$day; if (strlen($month)==1) $month = '0'.$month; echo "$year-$month-$day"; Quote Link to comment https://forums.phpfreaks.com/topic/221653-help-in-preg-match/#findComment-1147283 Share on other sites More sharing options...
.josh Posted December 14, 2010 Share Posted December 14, 2010 If your example date is m/d/y format (as in, January 5th, 2009) then you can do this: $newDate = date('Y-m-d',strtotime($oldDate)); Quote Link to comment https://forums.phpfreaks.com/topic/221653-help-in-preg-match/#findComment-1147300 Share on other sites More sharing options...
angela_john Posted December 18, 2010 Author Share Posted December 18, 2010 sir i have a sql.txt file and i am reading that file using php and want to find this date and replace with my MySQL database formate thats why i need preg match can some one help me Quote Link to comment https://forums.phpfreaks.com/topic/221653-help-in-preg-match/#findComment-1149001 Share on other sites More sharing options...
anandgodar Posted December 18, 2010 Share Posted December 18, 2010 Before moving to the regular expression i will suggest you to first read all the meanings of metacharacter in regular expression Quote Link to comment https://forums.phpfreaks.com/topic/221653-help-in-preg-match/#findComment-1149022 Share on other sites More sharing options...
sasa Posted December 19, 2010 Share Posted December 19, 2010 try to use mysql function STR_TO_DATE() http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_str-to-date Quote Link to comment https://forums.phpfreaks.com/topic/221653-help-in-preg-match/#findComment-1149159 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.