Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 simple question: converting string to datetime

Author  Topic 

deadfish
Starting Member

38 Posts

Posted - 2004-04-26 : 10:48:54
Hi,
I have the string like the following:

2004/4/26 PM 12:48:29
2004/4/26 PM 02:48:29
....

I would like to do comparision of the time part only. Shall I convert the string to datetime first? How to achieve this?

Thanks!

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-04-26 : 11:22:13
To compare the time part, I would look at the DatePart function in Books Online. Chances are it will do what you need.


Damian
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-04-26 : 11:30:07
I thought you went to bed....

I also find it very curious as to why the elders of this site did not impart any wisdom on the locked thread...


oh here....


DECLARE @a varchar(255), @b varchar(255)
, @c datetime, @d datetime

SELECT @a = '2004/4/26 PM 02:48:29', @b='2004/4/26 PM 12:48:29'
SELECT @c = CONVERT(datetime,'01/01/1900 '+RIGHT(@a,8)) , @d = CONVERT(datetime,'01/01/1900 '+RIGHT(@b,8))
SELECT DATEDIFF(mi,@c,@d) AS Minutes_Diff, @c AS s_Time, @d AS e_Time





Brett

8-)
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-04-26 : 11:37:44
quote:
Originally posted by X002548

I thought you went to bed....



Going to soon

quote:

I also find it very curious as to why the elders of this site did not impart any wisdom on the locked thread...




Why ? It was mainly a measuring contest.



Damian
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-04-26 : 11:41:08
quote:
Originally posted by Merkin

Why ? It was mainly a measuring contest.



No it wasn't...it was pure fantasy

Besides...it's no contest





Brett

8-)
Go to Top of Page
   

- Advertisement -