Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 08:27 AM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 09:28 AM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 11:01 AM
Hi Slash - that works perfectly! The results are '01:00:00'. Thank you!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 11:24 AM
No problem, glad that it worked for you 🙂