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
 General SQL Server Forums
 New to SQL Server Programming
 Minus hour from a Date

Author  Topic 

aoriju
Posting Yak Master

156 Posts

Posted - 2009-05-15 : 03:39:18
I have a Query To Add Hour(I can use this function to Restrict 20 hours after GetDate...its working...i want the reverse)

=======================================================
(
Convert(Datetime,Convert(Varchar(12),ORDMST.Daily_Order_Date,109)+ right(ORDDTL.Daily_Order_Departure_Time,7))
<= Dateadd(Hour,20,Convert(Datetime,Convert(Varchar(12),GETDATE(),109)+ '23:59:59:997'))

) --Avoid nextdays flight numbers
=======================================================

i want to restrict 20 hours before the Date

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-15 : 03:40:15
in short, minus 20 hours from now is
dateadd(hour, -20, getdate())


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-15 : 03:43:55
your this statement
quote:
<= Dateadd(Hour,20,Convert(Datetime,Convert(Varchar(12),GETDATE(),109)+ '23:59:59:997'))


can be change to


< dateadd(hour, 20, dateadd(day, datediff(day, 0, getdate()), 0))



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-15 : 03:52:14
AND this

Convert(Datetime,Convert(Varchar(12),ORDMST.Daily_Order_Date,109)+ right(ORDDTL.Daily_Order_Departure_Time,7))


to

dateadd(day, datediff(day, 0, ORDMST.Daily_Order_Date), 0) + convert(varchar(5), ORDDTL.Daily_Order_Departure_Time, 108)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

aoriju
Posting Yak Master

156 Posts

Posted - 2009-05-15 : 05:28:13
Thanks v Much
Go to Top of Page
   

- Advertisement -