<?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: Converting the mon-yy format to date, but showing null for output in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3572#M578</link>
    <description>&lt;P&gt;Hi Vartika,&lt;/P&gt;&lt;P&gt; Thanks for checking.&lt;/P&gt;&lt;P&gt; Unfortunately It was not yet resolved.. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Vicks&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 13:30:35 GMT</pubDate>
    <dc:creator>vicks</dc:creator>
    <dc:date>2023-06-09T13:30:35Z</dc:date>
    <item>
      <title>Converting the mon-yy format to date, but showing null for output</title>
      <link>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3569#M575</link>
      <description>&lt;P&gt;I have a date column that comes with month-year format and I am trying to convert that into dd-mm-yyyy format in pyspark&lt;/P&gt;&lt;P&gt; for example I have date column with value &lt;/P&gt;&lt;P&gt;Jan-2019&lt;/P&gt;&lt;P&gt;Feb-2020&lt;/P&gt;&lt;P&gt;Mar-2020&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the output I am expecting is &lt;/P&gt;&lt;P&gt;01/01/2019&lt;/P&gt;&lt;P&gt;01/02/2020&lt;/P&gt;&lt;P&gt;01/03/2020&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is he code I have written but that comes with null values&lt;/P&gt;&lt;P&gt;df2 = input_df.withColumn("mon-yr",to_date(col("mon-yr"),"MM/dd/yyyy"))&lt;/P&gt;&lt;P&gt;df2.show()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; any help is appreciated &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Vicks&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2023 06:52:00 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3569#M575</guid>
      <dc:creator>vicks</dc:creator>
      <dc:date>2023-06-06T06:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: Converting the mon-yy format to date, but showing null for output</title>
      <link>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3570#M576</link>
      <description>&lt;P&gt;Hi @vikram sinhha​&amp;nbsp;, The issue is happening because the input you are providing is not a valid date format. to_date expects you to provide the correct date format. You need to add the date value to the mon-yr column before passing to to_date function&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 14:20:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3570#M576</guid>
      <dc:creator>Lakshay</dc:creator>
      <dc:date>2023-06-08T14:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: Converting the mon-yy format to date, but showing null for output</title>
      <link>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3571#M577</link>
      <description>&lt;P&gt;Hi @vikram sinhha​,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope everything is going great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does @Lakshay Goel​'s answer help? If it does, would you be happy to mark it as best? If it doesn't, please tell us so we can help you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 11:44:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3571#M577</guid>
      <dc:creator>Vartika</dc:creator>
      <dc:date>2023-06-09T11:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting the mon-yy format to date, but showing null for output</title>
      <link>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3572#M578</link>
      <description>&lt;P&gt;Hi Vartika,&lt;/P&gt;&lt;P&gt; Thanks for checking.&lt;/P&gt;&lt;P&gt; Unfortunately It was not yet resolved.. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Vicks&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 13:30:35 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3572#M578</guid>
      <dc:creator>vicks</dc:creator>
      <dc:date>2023-06-09T13:30:35Z</dc:date>
    </item>
    <item>
      <title>Re: Converting the mon-yy format to date, but showing null for output</title>
      <link>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3573#M579</link>
      <description>&lt;P&gt;@vikram sinhha​&amp;nbsp;: does this answer help?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To convert the date column from the "month-year" format to "dd-mm-yyyy" format in PySpark, you can follow these steps:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;First, you need to add a day component to your date values since the to_date() function requires a complete date. You can use the concat() function to append the day to the month-year values.&lt;/LI&gt;&lt;LI&gt;Then, you can use the to_date() function with the appropriate date format to parse the modified date values.&lt;/LI&gt;&lt;LI&gt;Finally, you can use the date_format() function to convert the parsed dates into the desired "dd-mm-yyyy" format.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Here's an example of how you can modify your code to achieve the desired output:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;from pyspark.sql.functions import concat, lit, to_date, date_format
&amp;nbsp;
df2 = input_df.withColumn("mon-yr-day", concat(col("mon-yr"), lit("-01")))
df2 = df2.withColumn("date", to_date(col("mon-yr-day"), "MMM-yyyy-dd"))
df2 = df2.withColumn("formatted_date", date_format(col("date"), "dd/MM/yyyy"))
&amp;nbsp;
df2.show()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the above code, we first added a day component ("01") to the month-year values using concat() and lit("-01"). Then, we used to_date() to parse the modified dates with the format "MMM-yyyy-dd". Finally, we used date_format() to convert the parsed dates into the "dd/MM/yyyy" format. This should give you the expected output:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;+--------+----------+--------------+
| mon-yr |   date   | formatted_date|
+--------+----------+--------------+
|Jan-2019|2019-01-01|    01/01/2019|
|Feb-2020|2020-02-01|    01/02/2020|
|Mar-2020|2020-03-01|    01/03/2020|
+--------+----------+--------------+&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 14:25:34 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3573#M579</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-06-13T14:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Converting the mon-yy format to date, but showing null for output</title>
      <link>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3574#M580</link>
      <description>&lt;P&gt;Hi @vikram sinhha​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We haven't heard from you since the last response from @Suteja Kanuri​&amp;nbsp; . Kindly share the information with us, and in return, we will provide you with the necessary solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thanks and Regards&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 07:04:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/converting-the-mon-yy-format-to-date-but-showing-null-for-output/m-p/3574#M580</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-06-14T07:04:49Z</dc:date>
    </item>
  </channel>
</rss>

