SetToLoki Posted October 21, 2007 Share Posted October 21, 2007 I seem to be posting alot of problems today, this is what happens when you don't code anything in years. Anyway I have a string that looks like 21-Feb-06 and I want to turn it into a date that I can insert into a mysql date field. any quick way to do this? found strtotime() but it just isn't working for me just uploads 0000-00-00 00:00:00 Link to comment https://forums.phpfreaks.com/topic/74137-solved-date-from-string/ Share on other sites More sharing options...
SetToLoki Posted October 21, 2007 Author Share Posted October 21, 2007 function explodedate($date) { $explodedate = explode("-", $date); $year = $explodedate[2]; $month = $explodedate[1]; $day = $explodedate[0]; if ($month == 'Jan') { $month = 01; } if ($month == 'Feb') { $month = 02; } if ($month == 'Mar') { $month = 03; } if ($month == 'Apr') { $month = 04; } if ($month == 'May') { $month = 05; } if ($month == 'Jun') { $month = 06; } if ($month == 'Jul') { $month = 07; } if ($month == 'Aug') { $month = 08; } if ($month == 'Sep') { $month = 09; } if ($month == 'Oct') { $month = 10; } if ($month == 'Nov') { $month = 11; } if ($month == 'Dec') { $month = 12; } return date("Ymd",strtotime($year."-".$month."-".$day)); } Figured it out for myself. Link to comment https://forums.phpfreaks.com/topic/74137-solved-date-from-string/#findComment-374404 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.