<?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 Convert Date String to Date type Returning null in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/convert-date-string-to-date-type-returning-null/m-p/79502#M7856</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am using Databricks SQL and I am converting a integer field which is of format ('20240719' or 'yyyyMMdd'),&lt;BR /&gt;now I am able to convert it to date type using&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;to_date(forecastedHorizonPeriodDate,'yyyyMMdd')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I then tried to change the format of this date using the date_format function like&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;date_format(to_date(forecastedHorizonPeriodDate,'yyyyMMdd'),'MM/dd/yyyy')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;However this function returns a String,&amp;nbsp;&lt;BR /&gt;If I use the to_date function on top of this I am getting null&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;TO_DATE(date_format(to_date(forecastedHorizonPeriodDate,'yyyyMMdd'),'MM/dd/yyyy'))&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;Is there a way for me to convert this String type field to Date retaining the format ?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;date_format(to_date(forecastedHorizonPeriodDate,'yyyyMMdd'),'MM/dd/yyyy')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;Input field and type : '20240719' and Integer&lt;BR /&gt;Expected type and format : 07/19/2024 and Date&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is it possible for the date field to be of this format ?&amp;nbsp;&lt;BR /&gt;or does sql table only allow yyyy-mm-dd format for date?&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 19 Jul 2024 23:01:21 GMT</pubDate>
    <dc:creator>Dp15</dc:creator>
    <dc:date>2024-07-19T23:01:21Z</dc:date>
    <item>
      <title>Convert Date String to Date type Returning null</title>
      <link>https://community.databricks.com/t5/get-started-discussions/convert-date-string-to-date-type-returning-null/m-p/79502#M7856</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am using Databricks SQL and I am converting a integer field which is of format ('20240719' or 'yyyyMMdd'),&lt;BR /&gt;now I am able to convert it to date type using&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;to_date(forecastedHorizonPeriodDate,'yyyyMMdd')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I then tried to change the format of this date using the date_format function like&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;date_format(to_date(forecastedHorizonPeriodDate,'yyyyMMdd'),'MM/dd/yyyy')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;However this function returns a String,&amp;nbsp;&lt;BR /&gt;If I use the to_date function on top of this I am getting null&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;TO_DATE(date_format(to_date(forecastedHorizonPeriodDate,'yyyyMMdd'),'MM/dd/yyyy'))&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;Is there a way for me to convert this String type field to Date retaining the format ?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;date_format(to_date(forecastedHorizonPeriodDate,'yyyyMMdd'),'MM/dd/yyyy')&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;&lt;SPAN&gt;Input field and type : '20240719' and Integer&lt;BR /&gt;Expected type and format : 07/19/2024 and Date&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is it possible for the date field to be of this format ?&amp;nbsp;&lt;BR /&gt;or does sql table only allow yyyy-mm-dd format for date?&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 19 Jul 2024 23:01:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/convert-date-string-to-date-type-returning-null/m-p/79502#M7856</guid>
      <dc:creator>Dp15</dc:creator>
      <dc:date>2024-07-19T23:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date String to Date type Returning null</title>
      <link>https://community.databricks.com/t5/get-started-discussions/convert-date-string-to-date-type-returning-null/m-p/79506#M7857</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/95713"&gt;@Dp15&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;It's not possible. Spark does not support date types formatted in some other way except for yyyy-MM-dd. If you need another format, you will need to again convert the date type into string type, but with the format which you need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jul 2024 02:24:17 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/convert-date-string-to-date-type-returning-null/m-p/79506#M7857</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2024-07-20T02:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Date String to Date type Returning null</title>
      <link>https://community.databricks.com/t5/get-started-discussions/convert-date-string-to-date-type-returning-null/m-p/79874#M7858</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thank you for your answer&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2024 13:25:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/convert-date-string-to-date-type-returning-null/m-p/79874#M7858</guid>
      <dc:creator>Dp15</dc:creator>
      <dc:date>2024-07-22T13:25:20Z</dc:date>
    </item>
  </channel>
</rss>

