Wednesday, March 7, 2012

how to get only weekdays

Using SS2000, in QA I want to return data for only days Monday thru Friday.
Is there a way to do this? Is there some function that will give me only the
weekdays?
Thanks,
Dan D.
Dan,
Check http://www.aspfaq.com/show.asp?id=2519.
Dejan Sarka, SQL Server MVP
Mentor
www.SolidQualityLearning.com
"Dan D." <DanD@.discussions.microsoft.com> wrote in message
news:B7E42041-0ADA-4AFA-8512-8EF4806E33DC@.microsoft.com...
> Using SS2000, in QA I want to return data for only days Monday thru
> Friday.
> Is there a way to do this? Is there some function that will give me only
> the
> weekdays?
> Thanks,
> --
> Dan D.
|||Thanks Dejan. I'll take a look at that.
Dan D.
"Dejan Sarka" wrote:

> Dan,
> Check http://www.aspfaq.com/show.asp?id=2519.
> --
> Dejan Sarka, SQL Server MVP
> Mentor
> www.SolidQualityLearning.com
> "Dan D." <DanD@.discussions.microsoft.com> wrote in message
> news:B7E42041-0ADA-4AFA-8512-8EF4806E33DC@.microsoft.com...
>
>
|||You could use the DAY function to extract the numeric day of the week
select DAY(getdate())
This would give you all Sundays, for example.
SELECT * FROM Table1 where DAY(YourDateField) = 1
If you need to account for holidays or other more complex date calculations
the calendar table is the way to go.
"Dan D." <DanD@.discussions.microsoft.com> wrote in message
news:B7E42041-0ADA-4AFA-8512-8EF4806E33DC@.microsoft.com...
> Using SS2000, in QA I want to return data for only days Monday thru
Friday.
> Is there a way to do this? Is there some function that will give me only
the
> weekdays?
> Thanks,
> --
> Dan D.
|||SELECT * FROM Table1 where DATEPART(dw, YourDateField) between 2 and 6
http://sqlservercode.blogspot.com/
|||I discovered that function. I also discovered datepart which is what I'm
using. Thanks Terri.
Dan D.
"Terri" wrote:

> You could use the DAY function to extract the numeric day of the week
> select DAY(getdate())
> This would give you all Sundays, for example.
> SELECT * FROM Table1 where DAY(YourDateField) = 1
> If you need to account for holidays or other more complex date calculations
> the calendar table is the way to go.
> "Dan D." <DanD@.discussions.microsoft.com> wrote in message
> news:B7E42041-0ADA-4AFA-8512-8EF4806E33DC@.microsoft.com...
> Friday.
> the
>
>
|||I came across datepart after some more looking. It works. Thanks SQL.
Dan D.
"SQL" wrote:

> SELECT * FROM Table1 where DATEPART(dw, YourDateField) between 2 and 6
> http://sqlservercode.blogspot.com/
>

No comments:

Post a Comment