<?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: timestamp date filter does not work in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129897#M48626</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122413"&gt;@collierd&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;The way I would tackle this would involve data time specifiers. Because your value is likely stored as a timestamp which you can see via the catalog explorer, you cannot compare it to a string value such as "&lt;SPAN&gt;2025-08-27T10:50:31.610+00:00".&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-08-27 130439.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/19402i7DF9632FCCDC099A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2025-08-27 130439.png" alt="Screenshot 2025-08-27 130439.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;To get around this you can use date time specifiers to convert the string into a timestamp using the below code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;SPAN&gt;to_timestamp(&lt;/SPAN&gt;&lt;SPAN&gt;'2025-08-27T10:50:31.610+00:00'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-08-27 130219.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/19403i309FC18BAA541E2C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2025-08-27 130219.png" alt="Screenshot 2025-08-27 130219.png" /&gt;&lt;/span&gt;&lt;P&gt;If your curious about these date time specifiers there is a fill list of them available here:&lt;BR /&gt;&lt;A href="https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datetime-pattern" target="_blank"&gt;https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datetime-pattern&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The basic idea is that you select the relevant specifier (i.e "y" for year) then repeat this character to match the length of the string (so for a 4 digit year you get "yyyy").&lt;BR /&gt;&lt;BR /&gt;I hope this helps but feel free to ask any further questions.&lt;BR /&gt;&lt;BR /&gt;Regards - Pilsner&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Aug 2025 12:10:28 GMT</pubDate>
    <dc:creator>Pilsner</dc:creator>
    <dc:date>2025-08-27T12:10:28Z</dc:date>
    <item>
      <title>timestamp date filter does not work</title>
      <link>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129886#M48620</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I have a column called &lt;SPAN&gt;LastUpdated&amp;nbsp;&lt;/SPAN&gt;defined as timestamp&lt;/P&gt;&lt;P&gt;If I select from the table it displays as (e.g.)&amp;nbsp;2025-08-27T10:50:31.610+00:00&lt;/P&gt;&lt;P&gt;How do I filter on this without having to be specific with the year, month, day, ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This does not work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;select * from available

where LastUpdated = '2025-08-27T10:50:31.610+00:00'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Feel like there's a better approach than&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;select * from available

where year(LastUpdated) = 2025

and month(LastUpdated) = 8

and day(LastUpdated) = 27

etc.&lt;/LI-CODE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Aug 2025 10:33:03 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129886#M48620</guid>
      <dc:creator>collierd</dc:creator>
      <dc:date>2025-08-27T10:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: timestamp date filter does not work</title>
      <link>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129891#M48622</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122413"&gt;@collierd&lt;/a&gt;, Try this:&lt;BR /&gt;&lt;BR /&gt;WHERE CAST(LastUpdated AS DATE) = DATE '2025-08-27';&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 11:40:21 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129891#M48622</guid>
      <dc:creator>WiliamRosa</dc:creator>
      <dc:date>2025-08-27T11:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: timestamp date filter does not work</title>
      <link>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129896#M48625</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122413"&gt;@collierd&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;You have many options here. You can use&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. &lt;STRONG&gt;Date Truncation&lt;/STRONG&gt; - which r&lt;SPAN&gt;eturns timestamp truncated to the unit (you can use day, quarter, month etc)&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%sql
SELECT 
   date_trunc('day', LastUpdated),
   LastUpdated
FROM (
  SELECT current_timestamp() as LastUpdated 
) src
WHERE date_trunc('day', LastUpdated) = '2025-08-27'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp; 2. You can use &lt;STRONG&gt;date casting&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;SELECT 
   CAST(LastUpdated AS DATE) As lastUpdatedCasted,
   LastUpdated
FROM (
  SELECT current_timestamp() as LastUpdated 
) src
WHERE CAST(LastUpdated AS DATE) = '2025-08-27'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. &lt;STRONG&gt;Range filtering&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT    
   LastUpdated
FROM (
  SELECT current_timestamp() as LastUpdated 
) src
WHERE LastUpdated &amp;gt;= '2025-08-27' 
  AND LastUpdated &amp;lt; '2025-08-28'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4.&amp;nbsp;&lt;STRONG&gt;Format Matching&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;%sql
SELECT 
   date_format(LastUpdated, 'yyyy-MM'),
   LastUpdated
FROM (
  SELECT current_timestamp() as LastUpdated 
) src
WHERE date_format(LastUpdated, 'yyyy-MM') = '2025-08'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 12:08:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129896#M48625</guid>
      <dc:creator>szymon_dybczak</dc:creator>
      <dc:date>2025-08-27T12:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: timestamp date filter does not work</title>
      <link>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129897#M48626</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122413"&gt;@collierd&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;The way I would tackle this would involve data time specifiers. Because your value is likely stored as a timestamp which you can see via the catalog explorer, you cannot compare it to a string value such as "&lt;SPAN&gt;2025-08-27T10:50:31.610+00:00".&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-08-27 130439.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/19402i7DF9632FCCDC099A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2025-08-27 130439.png" alt="Screenshot 2025-08-27 130439.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;To get around this you can use date time specifiers to convert the string into a timestamp using the below code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;SPAN&gt;to_timestamp(&lt;/SPAN&gt;&lt;SPAN&gt;'2025-08-27T10:50:31.610+00:00'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt; &lt;SPAN&gt;"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-08-27 130219.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/19403i309FC18BAA541E2C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2025-08-27 130219.png" alt="Screenshot 2025-08-27 130219.png" /&gt;&lt;/span&gt;&lt;P&gt;If your curious about these date time specifiers there is a fill list of them available here:&lt;BR /&gt;&lt;A href="https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datetime-pattern" target="_blank"&gt;https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-datetime-pattern&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;The basic idea is that you select the relevant specifier (i.e "y" for year) then repeat this character to match the length of the string (so for a 4 digit year you get "yyyy").&lt;BR /&gt;&lt;BR /&gt;I hope this helps but feel free to ask any further questions.&lt;BR /&gt;&lt;BR /&gt;Regards - Pilsner&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 12:10:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129897#M48626</guid>
      <dc:creator>Pilsner</dc:creator>
      <dc:date>2025-08-27T12:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: timestamp date filter does not work</title>
      <link>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129910#M48634</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;That's useful but I also need the time&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 14:05:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129910#M48634</guid>
      <dc:creator>collierd</dc:creator>
      <dc:date>2025-08-27T14:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: timestamp date filter does not work</title>
      <link>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129911#M48635</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;date_trunc is the moset useful here as it includes the time&lt;/P&gt;&lt;P&gt;date_format only references the date part - although that is useful&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 14:06:42 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129911#M48635</guid>
      <dc:creator>collierd</dc:creator>
      <dc:date>2025-08-27T14:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: timestamp date filter does not work</title>
      <link>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129915#M48636</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;to_timestamp works well&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 14:17:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129915#M48636</guid>
      <dc:creator>collierd</dc:creator>
      <dc:date>2025-08-27T14:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: timestamp date filter does not work</title>
      <link>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129916#M48637</link>
      <description>&lt;P&gt;Glad I could help&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/122413"&gt;@collierd&lt;/a&gt;!&lt;BR /&gt;&lt;BR /&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/110502"&gt;@szymon_dybczak&lt;/a&gt;&amp;nbsp;I wasn't aware of the date_trunc function. I like the fact that you can pass simple terms, such as "day" in as a parameter, it makes it easy to read. Thanks!&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 14:49:12 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/timestamp-date-filter-does-not-work/m-p/129916#M48637</guid>
      <dc:creator>Pilsner</dc:creator>
      <dc:date>2025-08-27T14:49:12Z</dc:date>
    </item>
  </channel>
</rss>

