cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Snowflake filter Query giving empty results in Databricks, same query working in Snowflake.

Skv
New Contributor II

I am trying to fetch filter data based on date format on a date column. Below is the query forming in Databricks. In Databricks giving empty results.

SELECT * FROM Test.TestSchema.Address where TO_DATE(TO_VARCHAR(MODIFIEDDATE,'YYYY-MM-DD')) = '2023-09-10'

This Query formed in Databricks taken same in snowflake which is running fine and getting the data.

May I know what is the issue here.

2 REPLIES 2

Kaniz_Fatma
Community Manager
Community Manager

Hi @SkvThe issue you're experiencing could be using uppercaseโ€™ YYYY-MM-DDโ€™ in your date format.

In Spark 3.0 and above, which includes current versions of Databricks Runtime, the DateTimeFormatter doesn't recognizeโ€™ YYYY-MM-DDโ€™ as a valid date pattern. Instead, using the lowercaseโ€™ yyyy-MM-ddโ€™ would be best.

Therefore, your query should be:

sql
SELECT * FROM Test.TestSchema.Address where TO_DATE(TO_VARCHAR(MODIFIEDDATE,'yyyy-MM-dd')) = '2023-09-10'

This behaviour change is due to the migration from the combination of Julian and Gregorian calendars to the Proleptic Gregorian calendar in Spark 3.0 and above. This could be why your query works in Snowflake but not Databricks.

Sources:
- [Using datetime values in Spark 3.0 and above](https://kb.databricks.com/sql/using-datetime-values-in-spark-30-and-above)

Skv
New Contributor II

Changed the format with case Sensitive, same issue.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!