cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting 'time' from a 'timestamp' datatype in Databricks

TinaN
New Contributor III
We are loading a data source to Databricks that contains columns with 'Time' datatype.  Databricks converts this to 'Timestamp', so I am researching for a way to extract time only. This is what I came up with, but the result isn't quite right.  Is there a way to get a format of double digits (00:00)?
 
AS SELECT
   CONCAT(extract(hour from timestamp(sun_open)),
   ':',
   (extract(minute from timestamp(sun_open)))),
FROM table...
 
1) Input from sun_open column format is ,2024-06-01T01:00:00  
2) Result in Databricks is '1:0'
3) But I would like it to be '01:00:00'
 
Thank you,
Tina
1 ACCEPTED SOLUTION

Accepted Solutions

szymon_dybczak
Contributor III

Hi @TinaN ,

I check it in the evening, but try below: 

SELECT date_format(timestamp_column, 'HH:mm:ss') AS time_part
FROM your_table

View solution in original post

3 REPLIES 3

szymon_dybczak
Contributor III

Hi @TinaN ,

I check it in the evening, but try below: 

SELECT date_format(timestamp_column, 'HH:mm:ss') AS time_part
FROM your_table

TinaN
New Contributor III

Hi Slash - that works perfectly! The results are '01:00:00'. Thank you!

No problem, glad that it worked for you 🙂 

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