<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>databases Archives ~ Carlos Guzman</title>
	<atom:link href="https://carlosguzman.dev/tag/databases/feed/" rel="self" type="application/rss+xml" />
	<link>https://carlosguzman.dev/tag/databases/</link>
	<description>Senior Backend Developer - PHP - WordPress - REST APIs</description>
	<lastBuildDate>Thu, 25 Jun 2020 11:11:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>

<image>
	<url>https://carlosguzman.dev/wp-content/uploads/2019/06/favicon.ico</url>
	<title>databases Archives ~ Carlos Guzman</title>
	<link>https://carlosguzman.dev/tag/databases/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Datetime or Timestamp: readability matters</title>
		<link>https://carlosguzman.dev/datetime-or-timestamp-readability-matters/</link>
					<comments>https://carlosguzman.dev/datetime-or-timestamp-readability-matters/#respond</comments>
		
		<dc:creator><![CDATA[Carlos Guzmán]]></dc:creator>
		<pubDate>Fri, 12 Jun 2020 20:39:48 +0000</pubDate>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://carlosguzman.dev/?p=153</guid>

					<description><![CDATA[<p>When you are designing the schema of the database for your project and you need to store dates and times, then the question about what data type to use appears. Recently, I started a project to build a REST API and I used timestamps, a total mistake. Later, I was applying to a job and [&#8230;]</p>
<p>The post <a href="https://carlosguzman.dev/datetime-or-timestamp-readability-matters/">Datetime or Timestamp: readability matters</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">When you are designing the schema of the database for your project and you need to store dates and times, then the question about what data type to use appears. Recently, I started a project to build a REST API and I used timestamps, a total mistake. Later, I was applying to a job and again I decided to use timestamps in the project to show my skills. During the interview, the recruiter asked me why I decided to use timestamps and I realized that I didn’t make any analysis for this decision. I just wanted to try it…what a mistake.</p>



<p class="wp-block-paragraph">After this, I decided to investigate the pros and cons for the different options to store dates in a database. There are multiple articles about this topic. I want to highlight this <a rel="noreferrer noopener" aria-label="article where it is explained with details, examples and benchmarks using MySQL (opens in a new tab)" href="https://www.vertabelo.com/blog/what-datatype-should-you-use-to-represent-time-in-mysql-we-compare-datetime-timestamp-and-int/" target="_blank">article where it is explained with details, examples and benchmarks using MySQL</a>. Next is a too short summary about the article:</p>



<ul class="wp-block-list"><li>Using <em>DATETIME</em> allows to make SQL queries using functions related to dates(i.e: WEEKDAY in MySQL) in the SQL server. It allows to use dates from year 1000 to 9999. Queries over <em>DATETIME</em> are faster than queries over <em>TIMESTAMP</em>. The format used to print the <em>DATETIME</em> is user friendly and legible.</li><li>Using <em>TIMESTAMP</em> also allows to make SQL queries using functions related to dates. It allows dates until 2038 only. <em>TIMESTAMP</em> is lighter and it saves 1 byte of storage compared with <em>DATETIME</em>. The format used to print the <em>TIMESTAMP</em> is user friendly and legible.</li><li>Using <em>UNSIGNED INT</em> allows dates until 2106. It is not possible to use CURRENT_TIMESTAMP with this data type. SQL queries over INT are much faster than <em>DATETIME</em> and <em>TIMESTAMP</em>. To use date functions, the integer should be converted to a date(using function FROM_UNIXTIME in MySQL). In this case the SQL queries are slower than <em>DATETIME</em>.</li></ul>



<p class="wp-block-paragraph">One of the disadvantages with <em>TIMESTAMP</em> is the limit of 2038. Personally, I think that the SQL servers will change this in order to preserve compatibility with existing software using this datatype. It is not the same with <em>INT</em> because it is a datatype not intended to be used for dates. However there are integer types using more bytes of storage like <em>BIGINT</em> in MySQL.</p>



<p class="wp-block-paragraph">After my experience using timestamps in a REST API, definitely I will use <em>DATETIME</em> in next projects unless performance and storage are critical. When you are debugging, readability matters. When you see a bunch of numbers that not make sense, then you need to expend time converting those numbers to readable dates. Also working in the frontend, sometimes I needed to understand why I was getting those dates and then again it was stressful to see unintelligible numbers in the API response.</p>



<div class="wp-block-image"><figure class="aligncenter size-large"><img fetchpriority="high" decoding="async" width="322" height="277" src="https://carlosguzman.dev/wp-content/uploads/2020/06/timestamps-in-api-response.png" alt="datetime or timestamp: readability matters" class="wp-image-155" srcset="https://carlosguzman.dev/wp-content/uploads/2020/06/timestamps-in-api-response.png 322w, https://carlosguzman.dev/wp-content/uploads/2020/06/timestamps-in-api-response-300x258.png 300w" sizes="(max-width: 322px) 100vw, 322px" /><figcaption>Timestamps in a REST API response</figcaption></figure></div>



<p class="wp-block-paragraph">In my opinion, using <em>UNSIGNED INT</em> has sense if the performance of the app is critical <strong>AND</strong> you have one or multiple queries that doesn’t require to use date functions and they are in processes that run frequently in the app.</p>
<p>The post <a href="https://carlosguzman.dev/datetime-or-timestamp-readability-matters/">Datetime or Timestamp: readability matters</a> appeared first on <a href="https://carlosguzman.dev">Carlos Guzman</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://carlosguzman.dev/datetime-or-timestamp-readability-matters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk
Database Caching 3/55 queries in 0.047 seconds using Disk

Served from: carlosguzman.dev @ 2026-09-10 05:41:12 by W3 Total Cache
-->