Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.