Click here to Skip to main content
14,268,370 members
Rate this:
Please Sign up or sign in to vote.
See more:

I have a column "WeekBeginningDate" where each and every day date(format-yyyy/mm/dd) is stored.I have to fetch the data based on first and last day of the particular month.

For ex:-If current month is January,I have to get records that are in this month from 01-01-2013 to 31-01-2013 and for february,I have to get records from 01-02-2013 to 29-02-2013 and so on for mar,april......upto dec....

Can you people please help me out.


1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

datepart(month,getdate()) -- integer (1,2,3...)
,datepart(year,getdate()) -- integer
,datename(month,getdate()) -- January, February, etc

So you can select the month and the year as a string, the group based on that.
manasayarlagadda 8-Jan-13 3:34am
With this I can get only data related to only current month but I want data for all months........
Christian Graus 8-Jan-13 3:35am
Read my answer again. You can select the month and year as a single string, in your select statement, and then you can use 'group by' to group your data by month and year.
manasayarlagadda 8-Jan-13 3:56am
Sorry,I have tried it but its showing me the current month and current year data only.
Christian Graus 8-Jan-13 3:57am
Then you must be doing a where statement instead of a group by. Why not edit your post to show your code ? I can't fix what I can't see.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100