?
Solved

Extract time from timestamp in teradata while dropping seconds and milliseconds

Posted on 2014-09-10
6
Medium Priority
?
3,115 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 22

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 49

Accepted Solution

by:
PortletPaul earned 2000 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 49

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

Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

Question has a verified solution.

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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