Solved

Extract time from timestamp in teradata while dropping seconds and milliseconds

Posted on 2014-09-10
6
2,724 Views
Last Modified: 2014-09-10
I am trying to convert a timestamp formatted like the following example, 'yyyy-mm-dd hh:mm:ss.fff', to just the time in hours and minutes. I will be using this field later as a grouping dimension so it's important that the seconds and milliseconds are dropped. I would prefer that the result value still be interpreted as true time it is not required so if I were to get a string I would be okay. Lastly and most important the timestamp is in UTC time and I need it to be converted to American eastern.

Any assistance with this would be very much appreciated. Thank you
0
Comment
Question by:bignadad
  • 2
  • 2
6 Comments
 
LVL 21

Expert Comment

by:mcsween
ID: 40316040
This expression in SQL studio will give you HH:MM in -5 GMT (Eastern US) timezone assuming you pass in UTC.  You can replace GETUTCDATE() with your variable.
SELECT CONVERT(VARCHAR(5),DATEADD(hh,-5,GETUTCDATE()),8)

Open in new window

0
 
LVL 2

Author Comment

by:bignadad
ID: 40316101
Ah Ha. I was using convert(varchar, timestamp, 108) trying to convert it. In regards to the UTC conversion though. I was under the assumption that UTC time takes into consideration day light savings time so although on this current date we are -5, a few months from now we will be -4. With that said, wouldnt there have to be a way for the function to interpret the date that is being passed?
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 40316102
I have not worked with Terradata much and have not had to perform these conversions, so the following is just research

Under "TIMESTAMP-to-Character Conversion"

There is an example provided which suggests that you may CAST( ... AS FORMAT '')

so, it might be possible to get to hours and minutes like this:

CAST(your_ts_field AS FORMAT 'HH:MI')

or

CAST( CAST( your_ts_field AS FORMAT 'HH:MI' ) AS CHAR(5) )
0
 
LVL 2

Author Comment

by:bignadad
ID: 40316138
Just tried it out and worked like a charm. Thank you very much for your assistance.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40316141
A pleasure, thanks for the grading. Cheers, Paul

oh, & out of interest were you able to use it without converting to char or varchar?
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question