<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="106585" data-post-id="106585">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="salman" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/salman/120/12806_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  salman
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>When your schema looks like:</p>
<pre><code>schema "users" do
  ...
  timestamps()
end
</code></pre>
<p>How would you convert these to use :utc_timestamps?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="106585" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/difference-in-between-utc-datetime-and-naive-datetime-in-ecto/12551/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-106585" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="106585"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="106733" data-post-id="106733">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Nicd" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Nicd/120/2357_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Nicd
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>As documented here: <a href="https://hexdocs.pm/ecto/Ecto.Schema.html#timestamps/1" class="inline-onebox" rel="noopener nofollow ugc">Ecto.Schema — Ecto v3.14.0</a></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">timestamps(type: :utc_datetime)
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="106733" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/difference-in-between-utc-datetime-and-naive-datetime-in-ecto/12551/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-106733" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="106733"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="126852" data-post-id="126852">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ourway" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ourway/120/15577_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ourway
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>According to <a href="https://wiki.postgresql.org/wiki/Don%27t_Do_This#Date/Time%20storage" rel="noopener nofollow ugc">THIS</a> reference, we should almost never use timestamp (without time zone).</p>
<blockquote>
<h2>Don’t use timestamp (without time zone)</h2>
<p>Don’t use the timestamp type to store timestamps, use timestamptz (also known as timestamp with time zone) instead.</p>
<h3>Why not?</h3>
<p>timestamptz records a single moment in time. Despite what the name says it doesn’t store a timestamp, just a point in time described as the number of microseconds since January 1st, 2000 in UTC. You can insert values in any timezone and it’ll store the point in time that value describes. By default it will display times in your current timezone, but you can use at time zone to display it in other time zones.</p>
<p>Because it stores a point in time it will do the right thing with arithmetic involving timestamps entered in different timezones - including between timestamps from the same location on different sides of a daylight savings time change.</p>
<p>timestamp (also known as timestamp without time zone) doesn’t do any of that, it just stores a date and time you give it. You can think of it being a picture of a calendar and a clock rather than a point in time. Without additional information - the timezone - you don’t know what time it records. Because of that, arithmetic between timestamps from different locations or between timestamps from summer and winter may give the wrong answer.</p>
<p>So if what you want to store is a point in time, rather than a picture of a clock, use timestamptz.</p>
<p><a href="https://it.toolbox.com/blogs/josh-berkus/zone-of-misunderstanding-092811" rel="noopener nofollow ugc">More about timestamptz</a>.</p>
<h3>When should you?</h3>
<p>If you’re dealing with timestamps in an abstract way, or just saving and retrieving them from an app, where you aren’t going to be doing arithmetic with them then timestamp might be suitable.</p>
</blockquote> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="126852" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/difference-in-between-utc-datetime-and-naive-datetime-in-ecto/12551/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-126852" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="126852"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="126859" data-post-id="126859">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="ourway" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/ourway/120/15577_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  ourway
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Based on Postgres wiki:</p>
<blockquote>
<h2>Don’t use timestamp (without time zone) to store UTC times</h2>
<p>Storing UTC values in a  <code>timestamp without time zone</code>  column is, unfortunately, a practice commonly inherited from other databases that lack usable timezone support.</p>
<p>Use  <code>timestamp with time zone</code>  instead.</p>
<h3>Why not?</h3>
<p>Because there is no way for the database to know that UTC is the intended timezone for the column values.</p>
<p>This complicates many otherwise useful time calculations. For example, “last midnight in the timezone given by u.timezone” becomes this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">date_trunc('day', now() AT TIME ZONE u.timezone) AT TIME ZONE u.timezone AT TIME ZONE 'UTC'
</code></pre>
<p>And “the midnight prior to  <code>x.datecol</code>  in u.timezone” becomes this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">date_trunc('day', x.datecol AT TIME ZONE 'UTC' AT TIME ZONE u.timezone)
  AT TIME ZONE u.timezone AT TIME ZONE 'UTC'
</code></pre>
<h3>When should you?</h3>
<p>If compatibility with non-timezone-supporting databases trumps all other considerations.</p>
</blockquote> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="126859" data-batch-url="/posts/batch_likers">
                        5
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/difference-in-between-utc-datetime-and-naive-datetime-in-ecto/12551/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-126859" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="126859"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="156189" data-post-id="156189">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jung-hunsoo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jung-hunsoo/120/8455_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jung-hunsoo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<h3><a name="p-156189-when-you-create-a-new-record-in-default-ecto-timestamp-itll-be-created-with-utc-datetime-if-you-set-the-db-time-zone-properly-1" class="anchor" href="#p-156189-when-you-create-a-new-record-in-default-ecto-timestamp-itll-be-created-with-utc-datetime-if-you-set-the-db-time-zone-properly-1" aria-label="Heading link" rel="nofollow"></a>When You create a new record in default Ecto timestamp, it’ll be created with UTC datetime if you set the DB time zone properly.</h3>
<p>Here is the real data.</p>
<p>My local PostgreSQL DB has time zone of ‘Asia/Seoul’(+09:00).<br>
There’s a record created at <code>2019-12-26 10:50:23</code>.<br>
And in <code>psql</code>, it has <code>2019-12-26 01:50:23</code> in inserted_at.</p>
<p>But personally, I don’t think managing/manipulating tz on DB layer is a good idea. Your app will be dependent on PostgreSQL. Being aware of tz in timestamp is nonsense and a root of horror. Timestamp is best when used as UNIX timestamp.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="156189" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/difference-in-between-utc-datetime-and-naive-datetime-in-ecto/12551/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-156189" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="156189"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>