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
 date range

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-28

how 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]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-02-14 : 08:48:13
If is certain date to certain date is it possible?
Go to Top of Page

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]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-02-14 : 09:16:58
For example:

2012-01-01 to 2012-01-05
Go to Top of Page

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 query

1st 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]

Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-02-14 : 09:47:04
Oh I get what you meant.
Thanks alot!
Go to Top of Page

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 dates
is it passed from two variable?
if its @day parameter you explained in other thread, i've given a possible suggestion there

Anyways make sure you read this

http://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -