开发者

Uniformize date formats - how to?

I have two sources of information and those sources have dates in different formats.

Source A Wed, 17 Nov 2010 12:14:10 +0000 (from a rss feed)

Source B YYYY-MM-DD HH:MM:SS (from mysql datetime)

Request: I would like to order them by date to retrieve only the last occurrences.

But, and to put it even more difficult, those that are stored into the database should have in consideration the TIME. Because several records could be created on the same day.

I have control over the mysql output format to choose from. I don't have any control about the output coming from the rss feed.

This doesn't seem to be an easy achievement, and I'm wondering:

What could you suggest here?

Update: I was thinking about: Working source A like this: a) creating an array for months and the specific month number b) Retrive two chars after the first comma (or three if we count the space) (the day) c) Convert "Nov" to a number (by using the array previously created); d) Retr开发者_StackOverflow社区ieve the 2010 (not sure how); e) Place the year on the left, add a - place the month, and a -, place the day, add 00:00:00

At this time, they both will be equal and that could help... But, I feel really dummy about doing all this... :s Isn't there a smart way? :)

Over - php(zend) / mysql

Thanks a lot, MEM


If you can use PHP 5.3, I would use DateTime::createFromFormat() to normalize the date formats into a common format.

For mySQL dates:

$date = DateTime::createFromFormat('Y-m-d H:i:s', '2010-11-17');
echo $date->format('Y-m-d H:i:s');

For the RFC 2822 format, this should work (never tested it yet):

$date = DateTime::createFromFormat('r', 'Wed, 17 Nov 2010 12:14:10 +0000');
echo $date->format('Y-m-d H:i:s');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜