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

Convert Date to YYYYMMDD in databricks sql

BeginnerBob
New Contributor III

Hi,

I have a date column in a delta table called ADate. I need this in the format YYYYMMDD.

In TSQL this is easy. However, I can't seem to be able to do this without splitting the YEAR, MONTH and Day and concatenating them together.

Any ideas?

6 REPLIES 6

AmanSehgal
Honored Contributor III

@Lloyd Vickery​  could you please share a sample of what date looks like in your delta table and desired output?

Atanu
Esteemed Contributor
Esteemed Contributor

Vidula
Honored Contributor

Hello @Lloyd Vickery​ 

Hope all is well! Just wanted to check in if you were able to resolve your issue and would you be happy to share the solution or mark an answer as best? Else please let us know if you need more help. 

We'd love to hear from you.

Thanks!

hbenzineb
New Contributor II

Hello,

You can use the function date_format(your_date_column, 'yyyyMMdd')

JayDoubleYou42
New Contributor II

I'll share I'm having a variant of the same issue. I have a varchar field in the form YYYYMMDD which I'm trying to join to another varchar field from another table in the form of MM/DD/YYYY. Does anyone know of a way to do this in SPARK SQL without splitting the YEAR, MONTH and Day and concatenating them together? I've tried date_format, to_date, date, cast, and to_timestamp functions or different combinations of them, but haven't yet succeeded. Any help is appreciated. Thanks!

-werners-
Esteemed Contributor III

basically with to_date() and date_format() you can play with dates all you want.
to_date converts a string to a date (with the format the datestring is in as a parameter), and date_format converts a date to a string (with the format the output has to be in as a parameter).

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.