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.
Author |
Topic |
aiman
Starting Member
18 Posts |
Posted - 2007-06-21 : 01:30:26
|
I am going to Archive data for before 6th (1st Date to last 30/31th date) MonthMy Query is like:-- Declare @@DateTime DateTime,Set @@DateTime= GetDate()-?????? --[before 6th Mongtt]Select * from TableNamewhere DateTime>@@DateTime and DateTime<@@DateTimePlease Help with a standard way how can i handle this DateTime |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-21 : 01:37:15
|
quote: I am going to Archive data for before 6th (1st Date to last 30/31th date) Month
what do you mean by this ?Assuming today is June 21, what is the expected result ? KH |
 |
|
aiman
Starting Member
18 Posts |
Posted - 2007-06-21 : 01:47:02
|
Yes Today is 21th June , but i want to Collect Data For 1th Dec to 31th Dec 2006 and next 21th July will collect data for 1st january to 31th january |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-21 : 01:57:25
|
[code]SELECT today = GETDATE(), start_date = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 6, 0), end_date = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 5, -1)[/code] KH |
 |
|
aiman
Starting Member
18 Posts |
Posted - 2007-06-21 : 02:22:51
|
Thank you lots.. |
 |
|
aiman
Starting Member
18 Posts |
Posted - 2007-06-22 : 13:17:09
|
SELECT today = GETDATE(), start_date = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 6, 0), end_date = DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE()) - 5, -1)THis result give me one day less data.GetDate= 2007-06-22 23:15:02.013 start_date =2006-12-01 00:00:00.000 end_date=2006-12-31 00:00:00.000But I need like end_date=2006-12-31 23:59:59.000...Really sorry for this query again!!!! |
 |
|
|
|
|
|
|