{"id":3299,"date":"2019-11-20T20:58:08","date_gmt":"2019-11-20T18:58:08","guid":{"rendered":"https:\/\/supportex.net\/blog\/?p=3299"},"modified":"2019-11-20T20:58:08","modified_gmt":"2019-11-20T18:58:08","slug":"datetime-vs-timestamp-in-mysql-which-one-to-use","status":"publish","type":"post","link":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/","title":{"rendered":"DATETIME vs TIMESTAMP in MySQL, which one to use?"},"content":{"rendered":"<p>It is simple but confusing nonetheless. Official documentation does not help much, as both definitions looks almost the same.<\/p>\n<p>But there is a difference, which is important if your code handles time zones.<\/p>\n<p>With TIMESTAMP MySQL converts the value to UTC timezone to store it in database. Consequently, to SELECT the data MySQL runs a convertion from UTC to the current time zone.<br \/>\nFor example, you need TIMESTAMP if date\/time reflects individual users timezone.<\/p>\n<p>DATETIME is stored\/fetched unchanged.<\/p>\n<p>Keep in mind that if time zone settings change between storage and retrieval, you will get back different values for TIMESTAMP.<\/p>\n<p>Bottom line &#8211; use TIMESTAMP for reference to an absolute instant of time. Use DATETIME for consistency.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is simple but confusing nonetheless. Official documentation does not help much, as both definitions looks almost the same. But there is a difference, which is important if your code handles time zones. With TIMESTAMP MySQL converts the value to UTC timezone to store it in database. Consequently, to SELECT the data MySQL runs a&hellip; <\/p>\n<div class=\"readmore-wrapper\"><a href=\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/\" class=\"more-link\">Read <\/a><\/div>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[279],"tags":[199],"class_list":["post-3299","post","type-post","status-publish","format-standard","hentry","category-mysql-en","tag-mysql-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>DATETIME vs TIMESTAMP in MySQL, which one to use? &#8211; Supportex.NET blog<\/title>\n<meta name=\"description\" content=\"Difference between DATETIME vs TIMESTAMP data types in MySQL.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DATETIME vs TIMESTAMP in MySQL, which one to use? &#8211; Supportex.NET blog\" \/>\n<meta property=\"og:description\" content=\"Difference between DATETIME vs TIMESTAMP data types in MySQL.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/\" \/>\n<meta property=\"og:site_name\" content=\"Supportex.NET blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-20T18:58:08+00:00\" \/>\n<meta name=\"author\" content=\"bob\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"bob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/\"},\"author\":{\"name\":\"bob\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d\"},\"headline\":\"DATETIME vs TIMESTAMP in MySQL, which one to use?\",\"datePublished\":\"2019-11-20T18:58:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/\"},\"wordCount\":127,\"commentCount\":0,\"keywords\":[\"mysql\"],\"articleSection\":[\"mysql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/\",\"url\":\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/\",\"name\":\"DATETIME vs TIMESTAMP in MySQL, which one to use? &#8211; Supportex.NET blog\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\"},\"datePublished\":\"2019-11-20T18:58:08+00:00\",\"author\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d\"},\"description\":\"Difference between DATETIME vs TIMESTAMP data types in MySQL.\",\"breadcrumb\":{\"@id\":\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/supportex.net\/blog\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DATETIME vs TIMESTAMP in MySQL, which one to use?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\",\"url\":\"https:\/\/supportex.net\/blog\/en\/\",\"name\":\"Supportex.NET blog\",\"description\":\"Server and network management company\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d\",\"name\":\"bob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/affe5289af0481ab0f1461e54d1bb31b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/affe5289af0481ab0f1461e54d1bb31b?s=96&d=mm&r=g\",\"caption\":\"bob\"},\"url\":\"https:\/\/supportex.net\/blog\/author\/bob\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DATETIME vs TIMESTAMP in MySQL, which one to use? &#8211; Supportex.NET blog","description":"Difference between DATETIME vs TIMESTAMP data types in MySQL.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/","og_locale":"en_US","og_type":"article","og_title":"DATETIME vs TIMESTAMP in MySQL, which one to use? &#8211; Supportex.NET blog","og_description":"Difference between DATETIME vs TIMESTAMP data types in MySQL.","og_url":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/","og_site_name":"Supportex.NET blog","article_published_time":"2019-11-20T18:58:08+00:00","author":"bob","twitter_misc":{"Written by":"bob","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/#article","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/"},"author":{"name":"bob","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d"},"headline":"DATETIME vs TIMESTAMP in MySQL, which one to use?","datePublished":"2019-11-20T18:58:08+00:00","mainEntityOfPage":{"@id":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/"},"wordCount":127,"commentCount":0,"keywords":["mysql"],"articleSection":["mysql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/","url":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/","name":"DATETIME vs TIMESTAMP in MySQL, which one to use? &#8211; Supportex.NET blog","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/en\/#website"},"datePublished":"2019-11-20T18:58:08+00:00","author":{"@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d"},"description":"Difference between DATETIME vs TIMESTAMP data types in MySQL.","breadcrumb":{"@id":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/supportex.net\/blog\/2019\/11\/datetime-vs-timestamp-in-mysql-which-one-to-use\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/supportex.net\/blog\/en\/"},{"@type":"ListItem","position":2,"name":"DATETIME vs TIMESTAMP in MySQL, which one to use?"}]},{"@type":"WebSite","@id":"https:\/\/supportex.net\/blog\/en\/#website","url":"https:\/\/supportex.net\/blog\/en\/","name":"Supportex.NET blog","description":"Server and network management company","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/2425bc5aba0a9c1db43884a9f19f676d","name":"bob","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/affe5289af0481ab0f1461e54d1bb31b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/affe5289af0481ab0f1461e54d1bb31b?s=96&d=mm&r=g","caption":"bob"},"url":"https:\/\/supportex.net\/blog\/author\/bob\/"}]}},"_links":{"self":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/3299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/comments?post=3299"}],"version-history":[{"count":1,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/3299\/revisions"}],"predecessor-version":[{"id":3300,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/3299\/revisions\/3300"}],"wp:attachment":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/media?parent=3299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/categories?post=3299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/tags?post=3299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}