Okay So I have table content that has a update_time
column which is mysql DATETIME
column format. So an example time looks like this 2014-01-25 08:03:17
now this has been working okay , But I am attempting to build a sitemap for search engines and Google is telling me I need to represent my times in W3C Date and Time format which for my example time would look like so 2014-01-25T08:03:17-5:00
So this would be fairly simple to write a function in php to do this for me and call all over the place (like so)
function convert_to_w3c($time){
return str_replace(" ", "T", $time) . "-5:00";
}
however calling this 7000+ times just to return a sitemap seems super inefficient and as I am assuming I am not the only person to run into this problem as both these are fairly standard ways to represent time so is their some way to modify a mysql query to do this for me or is this my best option.
Sorry if this question has been asked (I did do some goolging but came up blank with a solution)
I don't see a problem with doing it 7000+ times, PHP should be able to do that reasonably quickly, and I assume you're caching the sitemap. Personally, I would use built-in datetime functionality:
$datetime = '2014-01-25 08:03:17';
echo date(DATE_ATOM, strtotime($datetime));
// '2014-01-25T08:03:17+01:00'
Where +01 is for my locale, you'll have another for your timezone.
But to answer your question, it is possible to do in MySQL, too - but it won't be locale aware, so you'll have to hardcode the -05:00 part in.
SELECT DATE_FORMAT(datetime_field, '%Y-%m-%dT%H:%m:%s-05:00') FROM table LIMIT 1
Notice also that it should be -05:00 according to the W3C standards, not -5:00.