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 |
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2012-02-14 : 08:39:31
|
| How to set the date range?select DATEADD(d, -1, CONVERT(date, GETUTCDATE()))refers to yesterday date.If i would like to range the date from 2012-01-01 to 2012-02-28how can i do that |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-02-14 : 08:43:58
|
[code]1st of the month = dateadd(month, datediff(month, 0, getdate()), 0)end of the month = dateadd(month, datediff(month, 0, getdate()) + 1, -1)[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2012-02-14 : 08:48:13
|
| If is certain date to certain date is it possible? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-02-14 : 08:57:37
|
quote: Originally posted by peace If is certain date to certain date is it possible?
what do you mean ? example ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2012-02-14 : 09:16:58
|
| For example:2012-01-01 to 2012-01-05 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-02-14 : 09:21:53
|
you want to find the 1st and end of the month for a date range ?just pass the from / to date into the query1st of the month = dateadd(month, datediff(month, 0, '2012-01-01'), 0)end of the month = dateadd(month, datediff(month, 0, '2012-01-01) + 1, -1) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2012-02-14 : 09:47:04
|
| Oh I get what you meant.Thanks alot! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-14 : 09:47:10
|
quote: Originally posted by peace For example:2012-01-01 to 2012-01-05
you need to explain as based on what rule you came up with above datesis it passed from two variable?if its @day parameter you explained in other thread, i've given a possible suggestion thereAnyways make sure you read thishttp://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|