<?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>topic Re: When formatting dates using the yyyyMMddHHmmssSSS pattern, an error occurred in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127262#M47901</link>
    <description>&lt;P&gt;hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/171339"&gt;@TheOC&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response.&lt;/P&gt;&lt;P&gt;If I don’t use lit, I get an error saying this column cannot be found.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Aug 2025 01:30:52 GMT</pubDate>
    <dc:creator>liu</dc:creator>
    <dc:date>2025-08-04T01:30:52Z</dc:date>
    <item>
      <title>When formatting dates using the yyyyMMddHHmmssSSS pattern, an error occurred</title>
      <link>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127048#M47838</link>
      <description>&lt;P&gt;An error occurred while converting a timestamp in the yyyyMMddHHmmssSSS format&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pyspark.sql.functions import to_timestamp_ntz, col, lit

df = spark.createDataFrame(
    [("20250730090833000")], ["datetime"])

df2 = df.withColumn("dateformat", to_timestamp_ntz(col("datetime"),lit("yyyyMMddHHmmssSSS")))

df2.display()
 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;error&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Text '20250730090833000' could not be parsed at index 0. Use `try_to_timestamp` to tolerate invalid input string and return NULL instead. SQLSTATE: 22007&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 07:35:40 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127048#M47838</guid>
      <dc:creator>liu</dc:creator>
      <dc:date>2025-07-31T07:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: When formatting dates using the yyyyMMddHHmmssSSS pattern, an error occurred</title>
      <link>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127053#M47839</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/175193"&gt;@liu&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;I suspect supplying the format as a column is the issue. Could you please try:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df2 = df.withColumn("dateformat", to_timestamp_ntz(col("datetime"),"yyyyMMddHHmmssSSS"))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 08:21:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127053#M47839</guid>
      <dc:creator>TheOC</dc:creator>
      <dc:date>2025-07-31T08:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: When formatting dates using the yyyyMMddHHmmssSSS pattern, an error occurred</title>
      <link>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127059#M47842</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/175193"&gt;@liu&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I think it could be related to following bug in Java. I suspect that internally&amp;nbsp;to_timestamp_ntz uses DateTimeFormatter.&lt;/P&gt;&lt;P&gt;&lt;A href="https://bugs.openjdk.org/browse/JDK-8031085" target="_blank"&gt;[JDK-8031085] DateTimeFormatter won't parse dates with custom format "yyyyMMddHHmmssSSS" - Java Bug System&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Now what's interesting, if the format has a decimal point before the miliseconds SSS, it can be parsed normally (&lt;BR /&gt;such as the format yyyyMMddHHmmss.SSS and enter 20240627235959.999).&lt;BR /&gt;&lt;BR /&gt;So one workaround you can try :&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pyspark.sql.functions import to_timestamp_ntz, col, lit

df = spark.createDataFrame(
    [("20250730090833000")], ["datetime"])

df2 =  df.select(
    "datetime",    
    to_timestamp(
        concat(
            substring("datetime", 1, 14),
            lit('.'),
            substring("datetime", 15, 3)
        ),
        'yyyyMMddHHmmss.SSS'
    ).alias('ts')
)

df2.display()

#20250730090833000&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Jul 2025 09:17:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127059#M47842</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-07-31T09:17:45Z</dc:date>
    </item>
    <item>
      <title>Re: When formatting dates using the yyyyMMddHHmmssSSS pattern, an error occurred</title>
      <link>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127262#M47901</link>
      <description>&lt;P&gt;hi&amp;nbsp;&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/171339"&gt;@TheOC&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response.&lt;/P&gt;&lt;P&gt;If I don’t use lit, I get an error saying this column cannot be found.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Aug 2025 01:30:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127262#M47901</guid>
      <dc:creator>liu</dc:creator>
      <dc:date>2025-08-04T01:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: When formatting dates using the yyyyMMddHHmmssSSS pattern, an error occurred</title>
      <link>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127263#M47902</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for your respons.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I did apply some substring  concatenation logic to make the conversion work, but the most straightforward way is still using the yyyyMMddHHmmssSSS format.&lt;BR /&gt;I checked the link you shared&amp;nbsp; this appears to be a bug dating back to 2013, yet it's still impacting us in 2025. That’s really unfortunate.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Aug 2025 01:48:36 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/when-formatting-dates-using-the-yyyymmddhhmmsssss-pattern-an/m-p/127263#M47902</guid>
      <dc:creator>liu</dc:creator>
      <dc:date>2025-08-04T01:48:36Z</dc:date>
    </item>
  </channel>
</rss>

