Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
Time - Adding minutes and seconds
28 posts, Page 2 of 3
««
1
2
3
»»
Time - Adding minutes and seconds
Rate Topic
Display Mode
Topic Options
Author
Message
neevmansoori
neevmansoori
Posted Saturday, December 22, 2012 8:01 AM
Forum Newbie
Group: General Forum Members
Last Login: Friday, February 15, 2013 5:02 AM
Points: 2,
Visits: 13
We sincerely thank you..
It Saves a lot of Efforts of mine.
Post #1399678
Jeff Moden
Jeff Moden
Posted Saturday, December 22, 2012 10:40 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 8:21 PM
Points: 32,893,
Visits: 26,765
neevmansoori (12/22/2012)
We sincerely thank you..
It Saves a lot of Efforts of mine.
Yeah, but as old as this post is, I'm not sure that it answers what needs to be done for display purposes if the following data is present...
Connect Time2 totalTime2
23:00:00.0000000 01:00:00.0000000
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1399692
dwain.c
dwain.c
Posted Sunday, December 23, 2012 5:47 PM
SSCrazy
Group: General Forum Members
Last Login: 2 days ago @ 12:42 AM
Points: 2,338,
Visits: 3,158
Jeff Moden (12/22/2012)
neevmansoori (12/22/2012)
We sincerely thank you..
It Saves a lot of Efforts of mine.
Yeah, but as old as this post is, I'm not sure that it answers what needs to be done for display purposes if the following data is present...
Connect Time2 totalTime2
23:00:00.0000000 01:00:00.0000000
I think what Jeff is alluding to without saying it is the TIME data type is a "time of day" and not a "time duration." Adding them together implies that at least one of the values is a "time duration." How can you add 4PM + 6PM?
Perhaps though, it has some meaning in another multiverse.
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1399777
Jeff Moden
Jeff Moden
Posted Sunday, December 23, 2012 10:39 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 8:21 PM
Points: 32,893,
Visits: 26,765
What I'm actually trying to get people to realize is that using JUST the time for this type of stuff (EndTime = StartTime + Duration) is the wrong thing to do unless it's ok to "wrap the clock" after midnight. If you have a duration that exceeds 24 hours starting just before midnight of one day, then you really need to show that the call or whatever duration your trying to portray ended two days later just after midnight.
In other words, both StartTime and EndTime must show the date AND the time for both.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1399801
dwain.c
dwain.c
Posted Sunday, December 23, 2012 11:49 PM
SSCrazy
Group: General Forum Members
Last Login: 2 days ago @ 12:42 AM
Points: 2,338,
Visits: 3,158
Jeff Moden (12/23/2012)
What I'm actually trying to get people to realize is that using JUST the time for this type of stuff (EndTime = StartTime + Duration) is the wrong thing to do unless it's ok to "wrap the clock" after midnight. If you have a duration that exceeds 24 hours starting just before midnight of one day, then you really need to show that the call or whatever duration your trying to portray ended two days later just after midnight.
In other words, both StartTime and EndTime must show the date AND the time for both.
Of course. Sorry Jeff, I didn't mean to speak for you.
But of interest, what is the meaning in the physical world of the following addition?
2012-12-21 05:00 + 2012-12-24 07:00
If your answer is that you're adding the number of days between Jan 1, 1900 and Dec 12, 2012 (+ 7 hours) to the date Jan 21, 2012 (at 5AM), I'm with you. I'm just saying it's a kludge (albeit a widely used one). Because MS hasn't been so kind to provide a specific type for a date/time interval.
Personally, my preference is to use the DATETIME to hold the date and an INT (or BIGINT) to hold the minutes, or if need be seconds, to represent the interval. Ignoring for the moment the issues you might encounter using BIGINT.
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1399820
Jeff Moden
Jeff Moden
Posted Monday, December 24, 2012 6:33 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 8:21 PM
Points: 32,893,
Visits: 26,765
No, no.... you were spot on. TIME columns are ok for durations of 1 day but aren't actually duration columns. I also have a hard time understanding why people would want to separate date and time even for display purposes unless they are, in fact, just trying to display duration. Certainly, I wouldn't store date and time separately.
I might store just the date if it's a column guaranteed to only ever need to be a whole date but then there's the problem of doing nasty little conversions like the one on this thread. For example, you asked if I was suggesting the following...
2012-12-21 05:00 + 2012-12-24 07:00
If the second date/time is supposed to be the duration and the first date/time is the start date, then kind of but not quite. If someone worked 1 hour, 13 minutes, and 59 seconds, then any of the following would work just fine to get the EndDate...
2012-12-21 05:00 + '01:13:59'
2012-12-21 05:00 + '1900-01-01 01:13:59' --Admittedly, confusing, but shows how things work.
StartDate + Duration -- Where both are data/time datatypes and the duration is stored as a result of (for example) '1900-01-01 01:13:59' .
Yeah... I know this stuff doesn't work for any of the "new" date/time datatypes. I think that MS really and unnecessarily made it a whole lot more difficult to do such simple things as adding a simple duration to a starting date and time. I wish they would have (no pun intended) spent the time making a proper "Duration" datatype that would allow you to store a (for example) 49 hour duration as something a little easier for folks to figure out other than 1900-01-03 01:00:00. For example, the following DOESN"T currently work...
SELECT Duration = CAST('49:00:00' AS DATETIME)
Instead, you have to go through a bunch of hooie to parse the hours, minutes, and seconds and then DATEADD each of those back to "0" (1900-01-01).
Same goes the other way around. Using subtraction between a start and end date/time is easy and accurate even across years. With the new date/time data types, you have to do something stupid like doing a DATEDIFF in milliseconds and then a DATEADD to "0" to reconvert it back to a date/time data type.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1399880
dwain.c
dwain.c
Posted Monday, December 24, 2012 5:35 PM
SSCrazy
Group: General Forum Members
Last Login: 2 days ago @ 12:42 AM
Points: 2,338,
Visits: 3,158
+100% (agreement). Merry Christmas Jeff!
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1400005
Jeff Moden
Jeff Moden
Posted Tuesday, December 25, 2012 7:46 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 8:21 PM
Points: 32,893,
Visits: 26,765
Merry Christmas Dwain.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1400051
dwain.c
dwain.c
Posted Tuesday, December 25, 2012 7:50 AM
SSCrazy
Group: General Forum Members
Last Login: 2 days ago @ 12:42 AM
Points: 2,338,
Visits: 3,158
Jeff Moden (12/25/2012)
Merry Christmas Dwain.
Let me see. Christmas morning where you are and here you are posting on the SSC forum.
You must want that 32,000th post pretty bad!
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1400054
Jeff Moden
Jeff Moden
Posted Saturday, December 29, 2012 10:42 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Yesterday @ 8:21 PM
Points: 32,893,
Visits: 26,765
dwain.c (12/25/2012)
Jeff Moden (12/25/2012)
Merry Christmas Dwain.
Let me see. Christmas morning where you are and here you are posting on the SSC forum.
You must want that 32,000th post pretty bad!
Nah... number of posts is a nice badge but that's not why I post. SQL isn't only my job, it's a hobby. Some folks do Sudoku, cross word puzzles, video games, etc... I like figuring out SQL problems.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1401189
« Prev Topic
|
Next Topic »
28 posts, Page 2 of 3
««
1
2
3
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.