cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

one of the date datatype format issue in pysaprk

KVNARK
Honored Contributor II

if anyone has encountered this date type format - 6/15/25 12:00 AM could you mention the right formatting to be used in Pyspark.

Thanks in advance!

4 REPLIES 4

UmaMahesh1
Honored Contributor III

Hi @KVNARK .​ 

You can use the below formatting to get it into a timestamp format...

to_timestamp('6/15/25 12:00 AM', 'MM/dd/yy hh:mm aa')

This will give you the timestamp like this -- 2025-06-15T00:00:00.000+0000

If you want only the date part, you can use to_date function.

Hope this helps...Cheers..

UmaMahesh1
Honored Contributor III

FYI... You also have to set set spark.sql.legacy.timeParserPolicy = LEGACY for the above to work..

Hubert-Dudek
Esteemed Contributor III

Without legacy, it will also work.image.png

SELECT to_timestamp('6/15/23 12:00 AM', 'M/dd/yy h:mm a')

Kaniz
Community Manager
Community Manager

Hi @KVNARK .​, We haven’t heard from you since the last response from @Uma Maheswara Rao Desula​ and @Hubert Dudek​ I was checking back to see if his suggestions helped you.

Or else, If you have any solution, please do share that with the community as it can be helpful to others.

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.