Solved

Extract time from timestamp in teradata while dropping seconds and milliseconds

Posted on 2014-09-10
6
2,560 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Just tried it out and worked like a charm. Thank you very much for your assistance.
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.‚Äč
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to recover a database from a user managed backup

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now