<?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: Getting date out of year and week in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6024#M2276</link>
    <description>&lt;P&gt;@Pien Derkx​&amp;nbsp;You can set the spark sql formatter to LEGACY and try your steps. Below is what worked for me. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;spark.conf.set("spark.sql.legacy.timeParserPolicy", "LEGACY")
&amp;nbsp;
df.withColumn("date_expected", to_date(col("dateinput", "uwwyyyy")).show()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;dateinput -&amp;gt; 3312023&lt;/P&gt;&lt;P&gt;Output came for dateexected -&amp;gt; 2023-03-29&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please try and let me know if this works. &lt;/P&gt;</description>
    <pubDate>Wed, 12 Apr 2023 09:50:10 GMT</pubDate>
    <dc:creator>pvignesh92</dc:creator>
    <dc:date>2023-04-12T09:50:10Z</dc:date>
    <item>
      <title>Getting date out of year and week</title>
      <link>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6021#M2273</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to get a date out of the columns year and week. The week format is not recognized. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df_loaded = df_loaded.withColumn("week_year", F.concat(F.lit("3"),F.col('Week'), F.col('Jaar')))&lt;/P&gt;&lt;P&gt;df_loaded = df_loaded.withColumn("date", F.to_date(F.col("week_year"), "uwwyyyy"))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm getting this error:&lt;/P&gt;&lt;P&gt;But it doesn't work and I get this error:&lt;/P&gt;&lt;P&gt;SparkUpgradeException: You may get a different result due to the upgrading of Spark 3.0: Fail to recognize 'uwwyyyy' pattern in the DateTimeFormatter. 1) You can set spark.sql.legacy.timeParserPolicy to LEGACY to restore the behavior before Spark 3.0. 2) You can form a valid datetime pattern with the guide from &lt;A href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html" alt="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html" target="_blank"&gt;https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas how to get from columns week &amp;amp; year to date in pyspark?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 07:16:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6021#M2273</guid>
      <dc:creator>Pien</dc:creator>
      <dc:date>2023-04-12T07:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Getting date out of year and week</title>
      <link>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6022#M2274</link>
      <description>&lt;P&gt;@Pien Derkx​&amp;nbsp;Hi, It would be really helpful if you can share some sample values that you are trying to typecast  along with your expected result so that we can try that. But I have seen that in the new Spark versions, you can just use a single literal for the date formats Ex MM/dd/yyyy --&amp;gt; m/d/y. This will work. Please see if you can try the same like uwy and let me know. &lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 07:59:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6022#M2274</guid>
      <dc:creator>pvignesh92</dc:creator>
      <dc:date>2023-04-12T07:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Getting date out of year and week</title>
      <link>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6023#M2275</link>
      <description>&lt;P&gt;Hi @Vigneshraja Palaniraj​&amp;nbsp;! Thanks for the help. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some example values: i'm getting year = 2023 and week = 13, then I'm making that into a string combining them:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df_loaded = df_loaded.withColumn("week_year", F.concat(F.lit("3"),F.col('Week'), F.col('Jaar')))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I add '3' in front because I want to have the wednesday of this week. This results in this string: &lt;B&gt;3132023&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which I use to get the date:&lt;/P&gt;&lt;P&gt;df_loaded = df_loaded.withColumn("date", F.to_date(F.col("&lt;B&gt;3132023&lt;/B&gt;"), "uwy"))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;desired date I would like to get here is: 2023/03/29 (the wednesday in week 13).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code gives no errors, but when I try to display the table, the error comes up&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 08:16:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6023#M2275</guid>
      <dc:creator>Pien</dc:creator>
      <dc:date>2023-04-12T08:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Getting date out of year and week</title>
      <link>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6024#M2276</link>
      <description>&lt;P&gt;@Pien Derkx​&amp;nbsp;You can set the spark sql formatter to LEGACY and try your steps. Below is what worked for me. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;spark.conf.set("spark.sql.legacy.timeParserPolicy", "LEGACY")
&amp;nbsp;
df.withColumn("date_expected", to_date(col("dateinput", "uwwyyyy")).show()&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;dateinput -&amp;gt; 3312023&lt;/P&gt;&lt;P&gt;Output came for dateexected -&amp;gt; 2023-03-29&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please try and let me know if this works. &lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 09:50:10 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6024#M2276</guid>
      <dc:creator>pvignesh92</dc:creator>
      <dc:date>2023-04-12T09:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Getting date out of year and week</title>
      <link>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6025#M2277</link>
      <description>&lt;P&gt;Hi @Pien Derkx​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for posting your question in our community! We are happy to assist you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 08:57:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6025#M2277</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-04-13T08:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Getting date out of year and week</title>
      <link>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6026#M2278</link>
      <description>&lt;P&gt;works, thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 11:13:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/getting-date-out-of-year-and-week/m-p/6026#M2278</guid>
      <dc:creator>Pien</dc:creator>
      <dc:date>2023-04-17T11:13:22Z</dc:date>
    </item>
  </channel>
</rss>

