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:ย 

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
Databricks Employee
Databricks Employee

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).

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