SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


difference


difference

Author
Message
kumar99ms
kumar99ms
SSC-Enthusiastic
SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)SSC-Enthusiastic (132 reputation)

Group: General Forum Members
Points: 132 Visits: 550
Hi Every body,

How can i find difference between these two could any please give some quire for this

14:12:43 CDT 06/14/2007

and

14:12:49 CDT 06/14/2007





Thanks
seth delconte
seth delconte
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1823 Visits: 1360
The answer is 6 seconds. Wink

But seriously, what kind of date format is that? I couldn't find any examples of converting from that format.

_________________________________
seth delconte
http://sqlkeys.com
Matt Miller (4)
Matt Miller (4)
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12203 Visits: 18574
Same question, asked in a new package -

http://www.sqlservercentral.com/Forums/FindPost585845.aspx

and

http://www.sqlservercentral.com/Forums/FindPost585851.aspx

No matter what you do with these - you will need to convert them first, then do whatever math you need to do.

You REALLY should keep these all together, since they are so closely related. You give the impression you're not reading the answers you're being given.

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
David O
David O
SSC Veteran
SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)SSC Veteran (278 reputation)

Group: General Forum Members
Points: 278 Visits: 928
Once you get your formatting issues fixed the function is datediff. Check out Books on line for the details of the function.
seth delconte
seth delconte
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1823 Visits: 1360
I agree, I think there's no way around the fact that you have to convert first. This should put you in the right direction for converting to standard MSSQL datetime format:

declare @oldDate varchar(50)
select @oldDate = '14:12:43 CDT 06/14/2007'

select convert(datetime,SUBSTRING(@oldDate,CHARINDEX(' ',@oldDate)+6,len(@oldDate))+' '+
SUBSTRING(@oldDate,0,CHARINDEX(' ',@oldDate)))


You can use a similar statement with an update or insert operation, then you will be free to use datediff or whatever to do the comparing!

_________________________________
seth delconte
http://sqlkeys.com
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85739 Visits: 41091
David O (10/15/2008)
Once you get your formatting issues fixed the function is datediff. Check out Books on line for the details of the function.


Actually, once converted, you can just subtract one from the other and format it in the hh:mm:ss.mmm format (24 hour) using CONVERT. And, be careful using DATEDIFF for days... it can give you and extra day if the times are just right.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search