<?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 odd results from 'to_timestamp()' in Data Engineering</title>
    <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3834498#M380</link>
    <description>&lt;P&gt;I had opened a ticket earlier in the week and am working with the support team. Thank you for looking a this.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Apr 2024 16:57:50 GMT</pubDate>
    <dc:creator>LeeGrantGeek</dc:creator>
    <dc:date>2024-04-12T16:57:50Z</dc:date>
    <item>
      <title>Getting odd results from 'to_timestamp()'</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3815963#M377</link>
      <description>&lt;P&gt;I am working with an open source Dataset (LA Crime Data from Kaggle). I am trying to clean up the data a little. I want a true timestamp for the Date of the reported crime. The Date (Date Rptd) and Time (TIME OCC) are text fields. I want to combine them to be a timestamp. I have removed the time that is in the date field,&amp;nbsp; all are 12:00:00 and transformed the Time field with zero padding and inserting a ':' between hours and minutes (e.g. 45 -&amp;gt; 00:45, 1424 -&amp;gt; 14:24. So all go so far. When I concat the two values into a new column I get this:&lt;/P&gt;&lt;P&gt;+----------------+&lt;BR /&gt;| TimeStamp_temp|&lt;BR /&gt;+----------------+&lt;BR /&gt;|02/20/2010 13:50|&lt;BR /&gt;|09/13/2010 00:45|&lt;BR /&gt;|08/09/2010 15:15|&lt;BR /&gt;|01/05/2010 01:50|&lt;BR /&gt;|01/03/2010 21:00|&lt;BR /&gt;|01/05/2010 16:50|&lt;BR /&gt;|01/08/2010 20:05|&lt;BR /&gt;|01/09/2010 21:00|&lt;BR /&gt;|01/09/2010 02:30|&lt;BR /&gt;|01/09/2010 21:00|&lt;BR /&gt;|01/14/2010 14:45|&lt;BR /&gt;|01/15/2010 20:00|&lt;BR /&gt;|01/15/2010 02:45|&lt;BR /&gt;|01/16/2010 17:45|&lt;BR /&gt;|01/16/2010 20:30|&lt;BR /&gt;|01/17/2010 17:35|&lt;BR /&gt;|01/23/2010 12:25|&lt;BR /&gt;|01/23/2010 11:00|&lt;BR /&gt;|01/23/2010 20:00|&lt;BR /&gt;|01/26/2010 18:20|&lt;BR /&gt;+----------------+&lt;BR /&gt;only showing top 20 rows&lt;/P&gt;&lt;P&gt;Then I call to_timestamp with 'MM/dd/YYYY HH:mm' as the format, I get this:&lt;/P&gt;&lt;P&gt;+-------------------+&lt;BR /&gt;| TimeStamp_Rptd|&lt;BR /&gt;+-------------------+&lt;BR /&gt;|2009-12-27 13:50:00|&lt;BR /&gt;|2009-12-27 00:45:00|&lt;BR /&gt;|2009-12-27 15:15:00|&lt;BR /&gt;|2009-12-27 01:50:00|&lt;BR /&gt;|2009-12-27 21:00:00|&lt;BR /&gt;|2009-12-27 16:50:00|&lt;BR /&gt;|2009-12-27 20:05:00|&lt;BR /&gt;|2009-12-27 21:00:00|&lt;BR /&gt;|2009-12-27 02:30:00|&lt;BR /&gt;|2009-12-27 21:00:00|&lt;BR /&gt;|2009-12-27 14:45:00|&lt;BR /&gt;|2009-12-27 20:00:00|&lt;BR /&gt;|2009-12-27 02:45:00|&lt;BR /&gt;|2009-12-27 17:45:00|&lt;BR /&gt;|2009-12-27 20:30:00|&lt;BR /&gt;|2009-12-27 17:35:00|&lt;BR /&gt;|2009-12-27 12:25:00|&lt;BR /&gt;|2009-12-27 11:00:00|&lt;BR /&gt;|2009-12-27 20:00:00|&lt;BR /&gt;|2009-12-27 18:20:00|&lt;BR /&gt;+-------------------+&lt;BR /&gt;only showing top 20 rows&lt;/P&gt;&lt;P&gt;All the dates are the same and note that this data starts in January 2010. So I decide to build a small data set with a Date and a Time:&lt;/P&gt;&lt;P&gt;Date, Time,&lt;BR /&gt;12/31/1961, 1147,&lt;BR /&gt;11/08/2019, 2032,&lt;BR /&gt;12/20/2021, 45&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I run this through the code and get this:&lt;/P&gt;&lt;P&gt;+----------+-----------+-------------------+&lt;BR /&gt;| Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |Padded_Time | New_Date|&lt;BR /&gt;+----------+-----------+-------------------+&lt;BR /&gt;|12/31/1961&amp;nbsp; &amp;nbsp;| 11:47&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| 1961-01-31 00:12:00|&lt;BR /&gt;|11/08/2019&amp;nbsp; &amp;nbsp;| 20:32&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| 2019-01-08 00:11:00|&lt;BR /&gt;|12/20/2021&amp;nbsp; &amp;nbsp;| 00:45&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| 2021-01-20 00:12:00|&lt;BR /&gt;+----------+-----------+-------------------+&lt;/P&gt;&lt;P&gt;Note that the new date is 11 month before the actual date and the hours/minutes are not correct. This has me baffled. Here is the code and csv data for the test:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#start code&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; pyspark.sql.types &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; DateType&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;from&lt;/SPAN&gt;&lt;SPAN&gt; pyspark.sql.functions &lt;/SPAN&gt;&lt;SPAN&gt;import&lt;/SPAN&gt;&lt;SPAN&gt; unix_timestamp, from_unixtime, concat, concat_ws, col, substring, to_timestamp, to_date, date_format, lit, lpad, regexp_replace&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;spark.conf.set(&lt;/SPAN&gt;&lt;SPAN&gt;"spark.sql.legacy.timeParserPolicy"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;"LEGACY"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_test = spark.read.format(&lt;/SPAN&gt;&lt;SPAN&gt;"csv"&lt;/SPAN&gt;&lt;SPAN&gt;).option(&lt;/SPAN&gt;&lt;SPAN&gt;"header"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;SPAN&gt;"true"&lt;/SPAN&gt;&lt;SPAN&gt;).load(&lt;/SPAN&gt;&lt;SPAN&gt;"Files/newtestdata-timestamp.csv"&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_test.drop(&lt;/SPAN&gt;&lt;SPAN&gt;' _c2'&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#df now is a Spark DataFrame containing CSV data from "Files/newtestdata-timestamp.csv".&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;display(df_test)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_test_time = df_test.withColumn(&lt;/SPAN&gt;&lt;SPAN&gt;'New_Date'&lt;/SPAN&gt;&lt;SPAN&gt;, to_timestamp(col(&lt;/SPAN&gt;&lt;SPAN&gt;'Date'&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;'mm/dd/yy'&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_test_time = df_test_time.withColumn(&lt;/SPAN&gt;&lt;SPAN&gt;'Padded_Time'&lt;/SPAN&gt;&lt;SPAN&gt;, lpad(col(&lt;/SPAN&gt;&lt;SPAN&gt;'Time'&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;4&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'0'&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_test_time = df_test_time.withColumn(&lt;/SPAN&gt;&lt;SPAN&gt;'Padded_Time'&lt;/SPAN&gt;&lt;SPAN&gt;, regexp_replace(col(&lt;/SPAN&gt;&lt;SPAN&gt;'Padded_Time'&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;SPAN&gt;'(&lt;/SPAN&gt;&lt;SPAN&gt;\\&lt;/SPAN&gt;&lt;SPAN&gt;d&lt;/SPAN&gt;&lt;SPAN&gt;{2}&lt;/SPAN&gt;&lt;SPAN&gt;)(&lt;/SPAN&gt;&lt;SPAN&gt;\\&lt;/SPAN&gt;&lt;SPAN&gt;d&lt;/SPAN&gt;&lt;SPAN&gt;{2}&lt;/SPAN&gt;&lt;SPAN&gt;)'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'$1:$2'&lt;/SPAN&gt;&lt;SPAN&gt;))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;df_test_time.select(&lt;/SPAN&gt;&lt;SPAN&gt;'Date'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'Padded_Time'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'New_Date'&lt;/SPAN&gt;&lt;SPAN&gt;).show()&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;#end code&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;CSV Data:&lt;/DIV&gt;&lt;DIV&gt;Date,Time,&lt;BR /&gt;12/31/1961,1147,&lt;BR /&gt;11/08/2019,2032,&lt;BR /&gt;12/20/2021,45&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Any help is appreciated.&lt;/DIV&gt;&lt;DIV&gt;Thanks,&lt;/DIV&gt;&lt;DIV&gt;Lee&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;The date is still in the yyyy-mm-dd format, but the dates displayed are 11 months before the actual dates&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Apr 2024 19:36:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3815963#M377</guid>
      <dc:creator>LeeGrantGeek</dc:creator>
      <dc:date>2024-04-06T19:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Getting odd results from 'to_timestamp()'</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3827913#M378</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="681234" data-lia-user-login="LeeGrantGeek" class="lia-mention lia-mention-user"&gt;LeeGrantGeek&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks for using Microsoft Fabric Community.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;At this time, we are reaching out to the internal team to get some help on this.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;We will update you once we hear back from them.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Appreciate your patience.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2024 15:10:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3827913#M378</guid>
      <dc:creator>v-cboorla-msft</dc:creator>
      <dc:date>2024-04-10T15:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: Getting odd results from 'to_timestamp()'</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3834487#M379</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="681234" data-lia-user-login="LeeGrantGeek" class="lia-mention lia-mention-user"&gt;LeeGrantGeek&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Apologize for the inconvenience.&lt;/P&gt;
&lt;P&gt;Please reach out to our support team to gain deeper insights and explore potential solutions&lt;SPAN&gt;. I&lt;/SPAN&gt;t's highly recommended that you reach out to our support team. Their expertise will be invaluable in suggesting the most appropriate approach.&lt;/P&gt;
&lt;P&gt;Please go ahead and raise a support ticket to reach our support team:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.fabric.microsoft.com/support" target="_blank" rel="noopener nofollow noreferrer"&gt;https://support.fabric.microsoft.com/support&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;After creating a Support ticket please provide the ticket number as it would help us to track for more information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2024 16:50:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3834487#M379</guid>
      <dc:creator>v-cboorla-msft</dc:creator>
      <dc:date>2024-04-12T16:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: Getting odd results from 'to_timestamp()'</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3834498#M380</link>
      <description>&lt;P&gt;I had opened a ticket earlier in the week and am working with the support team. Thank you for looking a this.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2024 16:57:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3834498#M380</guid>
      <dc:creator>LeeGrantGeek</dc:creator>
      <dc:date>2024-04-12T16:57:50Z</dc:date>
    </item>
    <item>
      <title>Re: Getting odd results from 'to_timestamp()'</title>
      <link>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3834504#M381</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="681234" data-lia-user-login="LeeGrantGeek" class="lia-mention lia-mention-user"&gt;LeeGrantGeek&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for creating support ticket. Could you please share&amp;nbsp;&lt;SPAN&gt;the ticket number here as it would help us to track for more information.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2024 17:02:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Data-Engineering/Getting-odd-results-from-to-timestamp/m-p/3834504#M381</guid>
      <dc:creator>v-cboorla-msft</dc:creator>
      <dc:date>2024-04-12T17:02:12Z</dc:date>
    </item>
  </channel>
</rss>

