Author |
Topic |
amurark
Yak Posting Veteran
55 Posts |
Posted - 2011-09-28 : 02:22:07
|
2010-10-21 14:49:26.0002010-10-21 14:49:26.0002010-09-13 18:52:12.0002010-09-13 18:54:52.0002010-09-14 14:22:14.0002010-09-13 13:39:08.0002010-09-13 13:48:38.0002010-09-13 19:40:15.000Ankita |
|
vmvadivel
Yak Posting Veteran
69 Posts |
Posted - 2011-09-28 : 02:22:55
|
So what is your question?Best RegardsVadivelhttp://vadivel.blogspot.com |
|
|
amurark
Yak Posting Veteran
55 Posts |
Posted - 2011-09-28 : 02:26:34
|
convert2010-10-21 14:49:26.0002010-09-13 18:52:12.0002010-09-13 18:54:52.0002010-09-14 14:22:14.0002010-09-13 13:39:08.0002010-09-13 13:48:38.0002010-09-13 19:40:15.000convert it into hours becasue i nedd to find the diffference between two dates in hours'Ankita |
|
|
vmvadivel
Yak Posting Veteran
69 Posts |
Posted - 2011-09-28 : 02:27:51
|
To extract the hour information from a given date make use of DATEPART function. DECLARE @dt datetimeSET @dt = '2010-10-21 14:49:26.000'SELECT DATEPART(hh, @dt);Best RegardsVadivelhttp://vadivel.blogspot.com |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-28 : 02:30:37
|
to get difference b/w two dates use datediff(hh,firstdate,seconddate)------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-09-28 : 02:31:41
|
quote: Originally posted by amurark convert2010-10-21 14:49:26.0002010-09-13 18:52:12.0002010-09-13 18:54:52.0002010-09-14 14:22:14.0002010-09-13 13:39:08.0002010-09-13 13:48:38.0002010-09-13 19:40:15.000convert it into hours becasue i nedd to find the diffference between two dates in hours'Ankita
Which 2 dates ? KH[spoiler]Time is always against us[/spoiler] |
|
|
amurark
Yak Posting Veteran
55 Posts |
Posted - 2011-09-28 : 02:31:53
|
its not static where i can use @dt = ''2010-10-21 14:49:26.000''step 1 -i converted the text into datetime as u told by the belwo query 'set dateformat dmyselect cast(convert(varchar(25), comments,111) AS datetime) from ocmqm1then the output came as Posted - 09/28/2011 : 02:26:34 convert2010-10-21 14:49:26.0002010-09-13 18:52:12.0002010-09-13 18:54:52.0002010-09-14 14:22:14.0002010-09-13 13:39:08.0002010-09-13 13:48:38.0002010-09-13 19:40:15.000now i need the output to be converted as hourws Ankita |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-28 : 02:33:03
|
you need the difference b/w above dates and current date in hours?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
vmvadivel
Yak Posting Veteran
69 Posts |
Posted - 2011-09-28 : 02:45:04
|
If you want to get the difference between two dates you gotto use DATEDIFF as already mentioned in the above post. Thought would show you few variations with that.DECLARE @stdt DATETIMESET @stdt = '2011-01-01 10:15:00.000'Declare @enddt DATETIMESET @enddt = '2011-01-01 11:35:00.000'--To get only HoursSELECT DATEDIFF(hh, @stdt,@enddt ) AS [Hours];--To get the result in MinutesSELECT CAST(DATEDIFF(ss, @stdt, @enddt) AS DECIMAL(10, 0)) / 60 AS [Minutes];--To get both Hours and MinutesSELECT DATEDIFF(hh, @stdt, @enddt) AS [Hours], DATEDIFF(mi,DATEADD(hh,DATEDIFF(hh, @stdt, @enddt),@stdt),@enddt) AS [Minutes];Best RegardsVadivelhttp://vadivel.blogspot.com |
|
|
jassi.singh
Posting Yak Master
122 Posts |
|
amurark
Yak Posting Veteran
55 Posts |
Posted - 2011-09-28 : 03:01:14
|
set dateformat dmyselect cast(convert(varchar(25),substring(comments,4,18),111) as datetime) as close_date ,number,requested_date, --from ocmqm1case when number is not nullthen datediff(hh,requested_date,cast(convert(varchar(25),substring(comments,4,18),111) as datetime)) else ''end as diff_hoursfrom ocmqm1order by diff_hoursdone thnks to everyone and spcl thnks to vmvadivelAnkita |
|
|
vmvadivel
Yak Posting Veteran
69 Posts |
Posted - 2011-09-28 : 03:12:48
|
You are welcome Ankita :)Best RegardsVadivelhttp://vadivel.blogspot.com |
|
|
|