<?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: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11222#M6232</link>
    <description>&lt;P&gt;The trick is to make sure your columns are recognized as &lt;B&gt;dates&lt;/B&gt;, otherwise they will be evaluated as strings.&lt;/P&gt;&lt;P&gt;"to_date(&amp;lt;datecol&amp;gt;, &amp;lt;date_format&amp;gt;) " does exactly this.&lt;/P&gt;&lt;P&gt;datecol is your column containing the date values, and date_format is the format in which your &lt;B&gt;existing&lt;/B&gt; date is formatted. In your case "MM/dd/yyyy".&lt;/P&gt;&lt;P&gt;This will return values of spark dateType.&lt;/P&gt;&lt;P&gt;When they are recognized as dates, you can start calculating with them.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Nov 2021 09:23:26 GMT</pubDate>
    <dc:creator>-werners-</dc:creator>
    <dc:date>2021-11-10T09:23:26Z</dc:date>
    <item>
      <title>i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11220#M6230</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="this are the dates in sql "&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2339i5D96DCB7B0EB0ED1/image-size/large?v=v2&amp;amp;px=999" role="button" title="this are the dates in sql " alt="this are the dates in sql " /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2330i72B111D23C467C6E/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 06:32:31 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11220#M6230</guid>
      <dc:creator>ahana</dc:creator>
      <dc:date>2021-11-10T06:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11222#M6232</link>
      <description>&lt;P&gt;The trick is to make sure your columns are recognized as &lt;B&gt;dates&lt;/B&gt;, otherwise they will be evaluated as strings.&lt;/P&gt;&lt;P&gt;"to_date(&amp;lt;datecol&amp;gt;, &amp;lt;date_format&amp;gt;) " does exactly this.&lt;/P&gt;&lt;P&gt;datecol is your column containing the date values, and date_format is the format in which your &lt;B&gt;existing&lt;/B&gt; date is formatted. In your case "MM/dd/yyyy".&lt;/P&gt;&lt;P&gt;This will return values of spark dateType.&lt;/P&gt;&lt;P&gt;When they are recognized as dates, you can start calculating with them.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 09:23:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11222#M6232</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2021-11-10T09:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11223#M6233</link>
      <description>&lt;P&gt;Exactly as @Werner Stinckens​&amp;nbsp;said. Additionally you can share your file and script so we can help better.&lt;/P&gt;&lt;P&gt;Your screenshot looks like excel. If it is excel format please check is all fields a data format (you can change also to number as every date is number of days from 31st December 1899). If it is csv format as werners said you need to specify format because for example 6/5/2021 can crush as it can be 5th June or 6th May.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 11:17:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11223#M6233</guid>
      <dc:creator>Hubert-Dudek</dc:creator>
      <dc:date>2021-11-10T11:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11224#M6234</link>
      <description>&lt;P&gt;@ahana ahana​&amp;nbsp; try this out:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%python
&amp;nbsp;
from pyspark.sql import functions as F
res = df.withColumn("start_date", F.to_date("start", "mm/dd/yyyy")).withColumn("end_date", F.to_date("end", "mm/dd/yyyy")).withColumn("date_diff", F.datediff("end_date","start_date"))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2336i971EE6E49FC17DD7/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 13:39:26 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11224#M6234</guid>
      <dc:creator>Sandeep</dc:creator>
      <dc:date>2021-11-12T13:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11225#M6235</link>
      <description>&lt;P&gt;Hi @ahana ahana​&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Did any of the replies helped you solve this issue? would you be happy to mark their answer as best so that others can quickly find the solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 23:49:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11225#M6235</guid>
      <dc:creator>jose_gonzalez</dc:creator>
      <dc:date>2021-11-12T23:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11226#M6236</link>
      <description>&lt;P&gt;i tried all way but it is still showing null&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 07:11:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11226#M6236</guid>
      <dc:creator>ahana</dc:creator>
      <dc:date>2021-11-15T07:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11227#M6237</link>
      <description>&lt;P&gt;I notice you do not have leading zeroes in your data format,&lt;/P&gt;&lt;P&gt;try M/d/yyyy instead.&lt;/P&gt;&lt;P&gt;&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;Maybe you have leading spaces too, so trim() might also help.&lt;/P&gt;&lt;P&gt;For sure this is not a bug because the date functions in Spark are rock solid.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 07:19:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11227#M6237</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2021-11-15T07:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11228#M6238</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2340i7AB04DAF2AEBC9B7/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2335iBFB0AB8BB55D3E29/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;the problem i am facing&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 07:54:32 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11228#M6238</guid>
      <dc:creator>ahana</dc:creator>
      <dc:date>2021-11-15T07:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11229#M6239</link>
      <description>&lt;P&gt;no its nt working i tried below function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;datediff(concat(&lt;/P&gt;&lt;P&gt;split(start_date, '/') [2],&lt;/P&gt;&lt;P&gt;'-',case&lt;/P&gt;&lt;P&gt;when split(start_date, '/') [0] &amp;lt; 10 then concat('0', split(start_date, '/') [0])&lt;/P&gt;&lt;P&gt;else split(start_date, '/') [0]&lt;/P&gt;&lt;P&gt;end,&lt;/P&gt;&lt;P&gt;'-',&lt;/P&gt;&lt;P&gt;case&lt;/P&gt;&lt;P&gt;when split(start_date, '/') [1] &amp;lt; 10 then concat('0', split(start_date, '/') [1])&lt;/P&gt;&lt;P&gt;else split(start_date, '/') [1]&lt;/P&gt;&lt;P&gt;end),  concat(split(end_date, '/') [2],&lt;/P&gt;&lt;P&gt;'-',case&lt;/P&gt;&lt;P&gt;when split(end_date, '/') [0] &amp;lt; 10 then concat('0', split(end_date, '/') [0])&lt;/P&gt;&lt;P&gt;else split(end, '/') [0]&lt;/P&gt;&lt;P&gt;end,&lt;/P&gt;&lt;P&gt;'-',&lt;/P&gt;&lt;P&gt;case&lt;/P&gt;&lt;P&gt;when split(end_date, '/') [1] &amp;lt; 10 then concat('0', split(end_date, '/') [1])&lt;/P&gt;&lt;P&gt;else split(end_date, '/') [1]&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;) )as diff&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 08:17:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11229#M6239</guid>
      <dc:creator>ahana</dc:creator>
      <dc:date>2021-11-15T08:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11230#M6240</link>
      <description>&lt;P&gt;no i am not satisfied with the given answer&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 08:19:36 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11230#M6240</guid>
      <dc:creator>ahana</dc:creator>
      <dc:date>2021-11-15T08:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11231#M6241</link>
      <description>&lt;P&gt;you have to use the exact format M/d/yyyy:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="image"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/2326iC2FCC312A67CE43A/image-size/large?v=v2&amp;amp;px=999" role="button" title="image" alt="image" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 09:03:27 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11231#M6241</guid>
      <dc:creator>-werners-</dc:creator>
      <dc:date>2021-11-15T09:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: i am trying to find different between two dates but i am getting null value in new column below are the dates in same format tryied to change the format but still it is not working is databricks</title>
      <link>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11232#M6242</link>
      <description>&lt;P&gt;thank u thank u soooo much it works thank u&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 11:19:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/i-am-trying-to-find-different-between-two-dates-but-i-am-getting/m-p/11232#M6242</guid>
      <dc:creator>ahana</dc:creator>
      <dc:date>2021-11-15T11:19:58Z</dc:date>
    </item>
  </channel>
</rss>

