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

What’s the Best Upgrade for My PC: Monitor or Specs?

I'm currently running a Ryzen 7 5700X with a 3080 Gaming Trio Z, plus I have 32GB of DDR4 RAM at 3000 MHz and...

How Much Longer Can My 3700X Keep Up with Gaming?

I'm currently using a Ryzen 3700X paired with a 7800XT and 32GB of RAM, and I've been playing most games at ultra settings in...

Is It Safe to Mount the Docker Socket in Read-Only Mode?

Hey everyone, I'm pretty new to Docker and I'm trying to understand the security implications of my setup. My Nginx proxy configuration includes '/var/run/docker.sock:/tmp/docker.sock:ro'...

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

xAI Grok Token Calculator

This tool is a simple xAI Grok token calculator that helps you estimate the number of tokens your input text might consume when working...

DeepSeek Token Calculator

This tool is a straightforward DeepSeek token calculator, created to help you estimate how many tokens your text may use when working with DeepSeek...

Google Gemini Token Calculator

This tool is a simple Google Gemini token calculator, designed to help you estimate how many tokens your text might use with models in...

Meta LLaMA Token Calculator

This tool is a basic Meta LLaMA token calculator, designed to give you a fast estimate of how many tokens your input text might...

Anthropic Claude AI Token Calculator

This tool is a simple Claude token calculator, built to help you quickly estimate token usage when working with Anthropic’s Claude models. It’s an...

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

Latest Posts

Latest Questions