<?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 Change datetime format from one to another without changing datatype in databricks sql in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91822#M38274</link>
    <description>&lt;P&gt;Change datetime"2002-01-01T00:00:00.000" to 'MM/dd/yyyy HH:mm:ss' format without changing datatype/ having it in datetime data type&lt;/P&gt;</description>
    <pubDate>Thu, 26 Sep 2024 08:10:52 GMT</pubDate>
    <dc:creator>richakamat130</dc:creator>
    <dc:date>2024-09-26T08:10:52Z</dc:date>
    <item>
      <title>Change datetime format from one to another without changing datatype in databricks sql</title>
      <link>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91822#M38274</link>
      <description>&lt;P&gt;Change datetime"2002-01-01T00:00:00.000" to 'MM/dd/yyyy HH:mm:ss' format without changing datatype/ having it in datetime data type&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 08:10:52 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91822#M38274</guid>
      <dc:creator>richakamat130</dc:creator>
      <dc:date>2024-09-26T08:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Change datetime format from one to another without changing datatype in databricks sql</title>
      <link>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91879#M38284</link>
      <description>&lt;P&gt;I presume then that the "datetime" string you provided is a string column?&lt;BR /&gt;If so, try the following code. This will not perform any transformation to timestamps:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pyspark.sql.functions import lit, split, concat

data = [{"date_string": "2002-01-01T00:00:00.000"}]

data_df = spark.createDataFrame(data) \
    .withColumn(
        "date_string_reformatted", concat(
            lit(split("date_string", "-")[1]), 
            lit("-"),
            lit(split(split("date_string", "-")[2], "T")[0]),
            lit("-"),
            lit(split("date_string", "-")[0]), 
            lit(" "),
            lit(split(split(split("date_string", "-")[2], "T")[1], "\.")[0]),
        )
    )

data_df.display()	&lt;/LI-CODE&gt;&lt;P&gt;The result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-09-26 143051.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11517i6CC7626F1AE9FB60/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2024-09-26 143051.png" alt="Screenshot 2024-09-26 143051.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 12:31:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91879#M38284</guid>
      <dc:creator>Mister-Dinky</dc:creator>
      <dc:date>2024-09-26T12:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Change datetime format from one to another without changing datatype in databricks sql</title>
      <link>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91882#M38286</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122865"&gt;@Mister-Dinky&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I think what&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/123034"&gt;@richakamat130&lt;/a&gt;&amp;nbsp;would like to obtain is to format datetime according to his needs, but to keep orginal data format (in this case datetime). Unfortunately, this is not possible in spark. If you want to have different display format then you need to have this conversion.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 13:03:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91882#M38286</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2024-09-26T13:03:49Z</dc:date>
    </item>
    <item>
      <title>Re: Change datetime format from one to another without changing datatype in databricks sql</title>
      <link>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91883#M38287</link>
      <description>&lt;P&gt;Ah, the "&lt;SPAN&gt;without changing datatype/ having it in datetime data type&lt;/SPAN&gt;" can be interpreted in that way as well. Then I agree with your statement.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 13:10:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91883#M38287</guid>
      <dc:creator>Mister-Dinky</dc:creator>
      <dc:date>2024-09-26T13:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Change datetime format from one to another without changing datatype in databricks sql</title>
      <link>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91888#M38290</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122865"&gt;@Mister-Dinky&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;As&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;&amp;nbsp;if you have a datetime, then you have a datetime.&lt;/P&gt;&lt;P&gt;What you see is just a format of defined in the Databricks UI. Other applications may display it differently depending on the defaults, regional formats etc.&lt;BR /&gt;&lt;BR /&gt;If you want to see datetime displayed differently in Databricks UI, then just navigate to your user settings and change it accordingly to your preferences:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_0-1727358771182.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11518iE221AF4CDFFA2C57/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_0-1727358771182.png" alt="filipniziol_0-1727358771182.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2024 13:53:24 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/change-datetime-format-from-one-to-another-without-changing/m-p/91888#M38290</guid>
      <dc:creator>filipniziol</dc:creator>
      <dc:date>2024-09-26T13:53:24Z</dc:date>
    </item>
  </channel>
</rss>

