Jump to content

[SOLVED] date from string


SetToLoki

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.