views:

930

answers:

4

I need to create a view that will automatically change from month to month to show only the current month (i.e. if current month is July - show items posted in July). Currently I have a view set up, but I have to manually change the month each time it changes (it's set up based on the first day of the current month and the last day of current month).

Thanks

+1  A: 

I believe there is no out of the box solution for that. One trick can be to write code in default view which would actually set the month for you or redirect to any other view. Something like

SPWeb web = SPContext.Current.Web;
string[] monthViewUrls = { "url1", "url2", ... };
string currentMonthUrl = monthViewUrls[DateTime.Now.Month-1];
Response.Redirect(currentMonthUrl );

Hope this helps.

Faheem
A: 

Can you live with the calendar view? That shows current month by default. Maybe you can start with that and try to customize it in SPD - it might retain its current month behavior.

Hafthor
+1  A: 

You can do this by turning the problem on its head.

First you need to add two calculated columns that will work out the start an the end of the month. (This example uses [Due Date] but you can use any date/time column)

"Start of Month"  =DATE(YEAR([Due Date]), MONTH([Due Date]), 1)

"End of Month"    =DATE(YEAR([Due Date]), MONTH([Due Date])+1,1)-1

Then you setup a filter in your view for

"Start of Month" is less than or equal to [Today]
 AND
"End of Month" is greater than or equal to [Today]

How To Use Filters in SharePoint to show items in the current Calendar Month

Ryan
A: 

Create a CC "NextMonth" that adds one month to your date =DATE(YEAR(Modified),MONTH(Modified)+1,"1")

create a view "ThisMonth" with this filter

"NextMonth" is greater than [Today]

this will always return the current month. can also be allpied to Year, to return current year

Create a CC "NextYear" that adds one year to your date =DATE(YEAR(Modified)+1,MONTH(Modified),"1")

create a view "ThisYear" with this filter

"NextYear" is greater than [Today]

Now the trick is to return a view for last Month. Let me know if you figure this out

larry