<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>article Introducing TIMESTAMP_NTZ in Apache Spark: The Timestamp Without Time Zone Type in Technical Blog</title>
    <link>https://community.databricks.com/t5/technical-blog/introducing-timestamp-ntz-in-apache-spark-the-timestamp-without/ba-p/50586</link>
    <description>&lt;P&gt;&lt;SPAN&gt;by Gengliang Wang,&amp;nbsp;Serge Rielau, Wenchen Fan, and Ivan Sadikov&lt;/SPAN&gt;&lt;/P&gt;
&lt;H1&gt;&lt;SPAN&gt;Introduction&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;As the volume and variety of data grow, so does the need for refined data types to ensure consistency, accuracy, and efficiency. Time data is notoriously challenging due to the complexities associated with time zones. Apache Spark, in its pursuit to be the de-facto processing engine for big data, has recognized this challenge. In Spark 3.4, the community introduces the TIMESTAMP_NTZ type, a timestamp that operates without considering time zones. This blog post delves into the TIMESTAMP_NTZ type, its motivations, and how to make the most of it on Apache Spark and Databricks platform.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;&lt;SPAN&gt;Why TIMESTAMP_NTZ?&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;Before the Apache Spark 3.4 release, the default and only timestamp type behaved similarly to Oracle's TIMESTAMP WITH LOCAL TIME ZONE, which is stored via normalizing to a standard time zone (UTC). However, Operating in multi-timezone environments or transferring data across systems presents unique challenges with timestamps. In these contexts, querying tables becomes intricate. Filtering based on timestamps requires not just an understanding of the data, but also an awareness of the source and target time zones. This added layer of complexity can make queries prone to errors and harder to maintain.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Hence, there's a clear need for a timestamp type that remains consistent, and independent of the session's time zone. Enter TIMESTAMP_NTZ, which stands for "timestamp without time zone". This data type allows users to represent precise moments without the nuances of time zones.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;&lt;SPAN&gt;Getting Started with TIMESTAMP_NTZ&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;Creating and manipulating tables/literals with the TIMESTAMP_NTZ type is simple. Here are some examples:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;&lt;FONT color="#FF0000"&gt;CREATE TABLE&lt;/FONT&gt; t(ts &lt;FONT color="#FF0000"&gt;TIMESTAMP_NTZ&lt;/FONT&gt;) using parquet;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ALTER TABLE&lt;/FONT&gt; t &lt;FONT color="#FF0000"&gt;ADD COLUMN&lt;/FONT&gt; (ts2 &lt;FONT color="#FF0000"&gt;TIMESTAMP_NTZ&lt;/FONT&gt;);&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;SELECT CAST&lt;/FONT&gt;('&lt;FONT color="#333399"&gt;2021-07-07 00:00:00&lt;/FONT&gt;' &lt;FONT color="#FF0000"&gt;AS&lt;/FONT&gt; &lt;FONT color="#FF0000"&gt;TIMESTAMP_NTZ&lt;/FONT&gt;);&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;SELECT&lt;/FONT&gt; &lt;FONT color="#FF0000"&gt;TIMESTAMP_NTZ&lt;/FONT&gt;'&lt;FONT color="#333399"&gt;2021-07-07 00:00:00&lt;/FONT&gt;';&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;A standout feature introduced in Spark 3.4 is the &lt;/SPAN&gt;&lt;A href="https://docs.databricks.com/en/sql/language-manual/functions/convert_timezone.html" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;convert_timezone()&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt; function. This function aids users in converting between time zones for TIMESTAMP_NTZ:&lt;/SPAN&gt;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;PRE&gt;&lt;FONT color="#808080"&gt;&lt;I&gt;&lt;SPAN&gt;-- Convert from 'America/Los_Angeles' to 'UTC'&lt;/SPAN&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;SELECT&lt;/FONT&gt;&lt;SPAN&gt; convert_timezone(&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;FONT color="#333399"&gt;America/Los_Angeles&lt;/FONT&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'UTC'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;FONT color="#FF0000"&gt;TIMESTAMP_NTZ&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;FONT color="#333399"&gt;2021-12-06 00:00:00&lt;/FONT&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;FONT color="#808080"&gt;&lt;I&gt;&lt;SPAN&gt;-- Output: 2021-12-06 08:00:00&lt;/SPAN&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;&lt;SPAN&gt;TIMESTAMP_NTZ vs. TIMESTAMP&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;Given the following table&amp;nbsp;&lt;STRONG&gt;recorded_times&lt;/STRONG&gt;:&lt;/SPAN&gt;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;PRE&gt;&lt;FONT color="#FF0000"&gt;SET TIME ZONE&lt;/FONT&gt; &lt;SPAN&gt;'&lt;FONT color="#333399"&gt;America/Los_Angeles&lt;/FONT&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;CREATE TABLE&lt;/FONT&gt;&lt;SPAN&gt; recorded_times (ts &lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;TIMESTAMP&lt;/FONT&gt;&lt;SPAN&gt;, ts_ntz &lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;TIMESTAMP_NTZ&lt;/FONT&gt;&lt;SPAN&gt;) &lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;USING&lt;/FONT&gt;&lt;SPAN&gt; parquet;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;INSERT INTO&lt;/FONT&gt;&lt;SPAN&gt; recorded_times &lt;/SPAN&gt;&lt;FONT color="#FF0000"&gt;VALUES&lt;/FONT&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;STRONG&gt;now&lt;/STRONG&gt;&lt;SPAN&gt;(), &lt;/SPAN&gt;&lt;STRONG&gt;now&lt;/STRONG&gt;&lt;SPAN&gt;());&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;SPAN&gt;In this 'America/Los_Angeles' time zone, both TIMESTAMP and TIMESTAMP_NTZ capture the same time, say &lt;/SPAN&gt;&lt;STRONG&gt;2023-10-05 17:00:00&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;However, when we switch our session to another time zone:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;SPAN&gt;&lt;FONT color="#FF0000"&gt;SET TIME ZONE&lt;/FONT&gt; '&lt;FONT color="#333399"&gt;America/New_York&lt;/FONT&gt;';&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;SELECT&lt;/FONT&gt; * &lt;FONT color="#FF0000"&gt;FROM&lt;/FONT&gt; recorded_times;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The TIMESTAMP value adjusts to reflect the new time zone&lt;/SPAN&gt;&lt;SPAN&gt;, while TIMESTAMP_NTZ remains consistent:&lt;/SPAN&gt;&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;Column type&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;In 'America/Los_Angeles'&amp;nbsp;Time Zone&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;In 'America/New_York' Time Zone&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;TIMESTAMP&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;2023-10-05 17:00:00&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;STRONG&gt;2023-10-05 20:00:00&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;TIMESTAMP_NTZ&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;2023-10-05 17:00:00&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="30px"&gt;&lt;STRONG&gt;2023-10-05 17:00:00&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;&lt;SPAN&gt;Interoperability and Support&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;The TIMESTAMP_NTZ type offers seamless conversion with Date, Timestamp, and String types. It's supported across Python, SQL, Scala, and Java in Spark. Moreover, it accommodates file sources such as Delta, Parquet, ORC, Avro, JSON, and CSV and ensures compatibility with Hive metastore and &lt;/SPAN&gt;&lt;A href="https://www.databricks.com/product/unity-catalog" target="_blank" rel="noopener"&gt;&lt;SPAN&gt;Unity Catalog&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;&lt;SPAN&gt;Wrapping Up&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P&gt;&lt;SPAN&gt;The introduction of the TIMESTAMP_NTZ feature in Spark SQL highlights Spark's commitment to addressing the evolving needs of its users. If you're grappling with timestamp data and want to sidestep the complications of time zones, TIMESTAMP_NTZ is your go-to feature.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Nov 2023 05:19:39 GMT</pubDate>
    <dc:creator>GengliangWang</dc:creator>
    <dc:date>2023-11-21T05:19:39Z</dc:date>
    <item>
      <title>Introducing TIMESTAMP_NTZ in Apache Spark: The Timestamp Without Time Zone Type</title>
      <link>https://community.databricks.com/t5/technical-blog/introducing-timestamp-ntz-in-apache-spark-the-timestamp-without/ba-p/50586</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Introducing TIMESTAMP_NTZ in Apache Spark: Understand its significance in the Spark ecosystem, and how it offers a consistent approach to timestamp data, eliminating multiple time zone hassles.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 05:19:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/introducing-timestamp-ntz-in-apache-spark-the-timestamp-without/ba-p/50586</guid>
      <dc:creator>GengliangWang</dc:creator>
      <dc:date>2023-11-21T05:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: Introducing TIMESTAMP_NTZ in Apache Spark: The Timestamp Without Time Zone Type</title>
      <link>https://community.databricks.com/t5/technical-blog/introducing-timestamp-ntz-in-apache-spark-the-timestamp-without/bc-p/124070#M681</link>
      <description>&lt;P&gt;Thanks for adding TIMESTAMP_NTZ timestamp.&lt;/P&gt;&lt;P&gt;It will be helpful if you add TIMESTAMP_TZ too which will store and display the time with original timezone.&lt;/P&gt;&lt;P&gt;Currently using TIMESTAMP data type, it is not possible to know the original timezone of that time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example: the timestamp value, '2025-01-01T01:10:10-07:00' which is UTC -7 timezone, if we store this as TIMESTAMP then during query it will convert to system's local timezone (for example UCT-5) and display as&amp;nbsp;'2025-01-01T03:10:10-05:00'. So we don't know what is the original timezone.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jul 2025 04:08:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/introducing-timestamp-ntz-in-apache-spark-the-timestamp-without/bc-p/124070#M681</guid>
      <dc:creator>SN</dc:creator>
      <dc:date>2025-07-05T04:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Introducing TIMESTAMP_NTZ in Apache Spark: The Timestamp Without Time Zone Type</title>
      <link>https://community.databricks.com/t5/technical-blog/introducing-timestamp-ntz-in-apache-spark-the-timestamp-without/bc-p/124071#M682</link>
      <description>&lt;P&gt;This is a nice feature - time zones / date times are almost always a headache. Thanks for the write up!&lt;/P&gt;</description>
      <pubDate>Sat, 05 Jul 2025 06:40:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/technical-blog/introducing-timestamp-ntz-in-apache-spark-the-timestamp-without/bc-p/124071#M682</guid>
      <dc:creator>TheOC</dc:creator>
      <dc:date>2025-07-05T06:40:28Z</dc:date>
    </item>
  </channel>
</rss>

