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
Solved

Extract time from timestamp in teradata while dropping seconds and milliseconds

Posted on 2014-09-10
6
2,783 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Read about achieving the basic levels of HRIS security in the workplace.
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…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

828 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