cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Unable to convert to date from datetime string with AM and PM

David_Billa
New Contributor II

Any help to understand why it's showing 'null' instead of the date value? It's showing null only for 12:00:00 AM and for any other values it's showing date correctly

TO_DATE("12/30/2022 12:00:00 AM", "MM/dd/yyyy HH:mm:ss a") AS tsDate

 

1 REPLY 1

Alberto_Umana
Databricks Employee
Databricks Employee

Hi @David_Billa,

Can you try with:

TO_TIMESTAMP("12/30/2022 12:00:00 AM", "MM/dd/yyyy hh:mm:ss a") AS tsDate

The issue you are encountering with the TO_DATE function returning null for the value "12:00:00 AM" is likely due to the format string not matching the input string correctly. The TO_DATE function in Databricks requires the format string to precisely match the input string for it to parse the date correctly

https://docs.databricks.com/ja/sql/language-manual/functions/to_timestamp.html

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group