May 1, 2014 at 3:39 pm
Hi
I have a field that is a string, but stores a time value as "09:45 AM"
I need to do calculations on time differences
for example
Starttime has the value "09:45 AM"
Endtime has the value "10:15 AM"
I need to show Endtime - starttime = "30 Minutes"
Thanks
Joe
May 2, 2014 at 2:33 am
SELECT
Starttime = CAST(Starttime AS TIME),
Endtime = CAST(Endtime AS TIME),
MinutesElapsed = DATEDIFF(minute, CAST(Starttime AS TIME), CAST(Endtime AS TIME))
FROM (SELECT Starttime = '09:45 AM', Endtime = '10:15 AM') d
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
May 2, 2014 at 7:46 am
Thanks Chris
Worked great, I guess I'll need to use CAST alot with the data in this table ๐
Have a nice weekend!!
May 2, 2014 at 8:09 am
You're welcome, you too! It's a bank holiday weekend here ๐
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply