Using MySQL Timestamp In a Google Sitemap Lastmod

The lastmod  field in sitemaps is subject to a lot of trouble for most people who are trying to build their own dynamic sitemaps. The main issue is that google only accepts a single type of timestamp and if it is now 100% correct it will throw a load of errors telling you the date is incorrect. I had a lot of difficulty finding the correct format to use for the timestamp. Quite often the solution would result in a date set to 1970, which of course was very incorrect. The solution below is how i was able to correctly use a MySQL timestamp in a Google sitemap for the lastmod field.

$datetime = new DateTime($row['Timestamp']);
$lastmod = $datetime->format('Y-m-d\TH:i:sP');

This will generate the correct output provided the input was first a valid SQL timestamp. One thing to be aware of and it is something that caused me to waste quite a lot of time. Even though you have updated the sitemap and the date is parsing correctly, Googles webmaster tools might still show the same error and will continue to show the error for a few minutes (even as far as an hour). As long as you are confident that the format is what it should be, wait a while and the webmaster tools page will eventually update correctly.

Related Articles

Related Questions

Looking for Recommendations for User-Friendly Arch-Based Distros

I've been using Ubuntu and Debian-based distributions for quite some time because of their strong support and wide selection of third-party software. However, I'm...

Having Grub Issues on Debian with Windows Detection

I'm running into some serious issues with Grub on my Debian setup where it doesn't seem to detect Windows at all. I've already tried...

What’s the Best Way for an Azure Runbook to Send Emails?

Hey everyone! I'm new to my current role and trying to navigate our environment. We have an existing runbook that sends out emails using...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Latest Tools

OpenAI Token Calculator

This tool is a simple OpenAI token calculator, web-based utility designed to help you quickly estimate the number of tokens in your text when...

List Sorting Tool

Welcome to our innovative list ordering and management tool. This next-level platform enables you to sort a list of items in ascending or descending...

Sudoku Solver

Welcome to our free online Sudoku solving tool, an interactive platform for puzzle enthusiasts seeking a break from a Sudoku conundrum. This advanced platform...

Apply Image Filters To Image

Digital imagery in the modern world is all about reinforcing emotions and stories behind each photo we take. To amplify this storytelling, we are...

Add Watermark To Image

As the world is increasingly consumed by digital media, protecting your original images is paramount. We are thrilled to introduce you to our innovative...

CSV To Xml Converter

Welcome to our CSV to XML converter tool, a convenient and user-friendly solution for all your data conversion needs. This versatile tool on our...

Latest Posts

Latest Questions