Solved Converting rrs-date format to MySQL date format

All your question about php
Post Reply
Peter_w
Posts: 28
Joined: Tue Aug 19, 2008 9:28 am

Solved Converting rrs-date format to MySQL date format

Post by Peter_w »

Hi,

Does anyone has fast way to convert the rrs-date format to MySQL date format?

Thanks,
chris
Site Admin
Posts: 180
Joined: Mon Jul 21, 2008 9:52 am

Re: Converting rrs-date format to MySQL date format

Post by chris »

strtotime is great function in php

Code: Select all

$mysql_date=date(Y-m-d', strtotime($rss_date)); 
this should do the trick.
mister_v
Posts: 177
Joined: Thu Mar 04, 2010 9:19 pm

Re: Converting rrs-date format to MySQL date format

Post by mister_v »

Hi,

strtotime() doesn't do it for me.

I have the following code:

Code: Select all

	  $pubdate=date('Y-m-d',strtotime($rssdate));
	  print $rssdate."\n";
	  print $pubdate."\n";
Wich results in:
Fri, 5 Mar 2010 08:00:00 System/Localtime
1970-01-01

My php version:
PHP 5.2.6
chris
Site Admin
Posts: 180
Joined: Mon Jul 21, 2008 9:52 am

Re: Converting rrs-date format to MySQL date format

Post by chris »

Hi,

I tested it with php version 5.2.10-2,
and it works OK.

result:
Fri, 5 Mar 2010 08:00:00 System/Localtime
2010-03-05

Try upgrading to the latest version.
chris
Site Admin
Posts: 180
Joined: Mon Jul 21, 2008 9:52 am

Re: Converting rrs-date format to MySQL date format

Post by chris »

As you only need the date.
Try it with only the first part:

Code: Select all

$date_array=explode(' ',$rssdate);
$newdate=$date_array[0].$date_array[1].$date_array[2].$date_array[3];
$pubdate=date('Y-m-d',strtotime($newdate));
print $newdate."\n";
print $pubdate."\n";
It should give a correct result:
Fri,5Mar2010
2010-03-05
mister_v
Posts: 177
Joined: Thu Mar 04, 2010 9:19 pm

Re: Converting rrs-date format to MySQL date format

Post by mister_v »

Thanks,

This works.
It gets the correct date.
Post Reply