I'm trying to SELECT records out of an Events Database (with an EventDate field as Date) that have a EventDate that is in the current month.
I have functions for calculating the first day of the month:
public string GetFirstofMonth(DateTime dt)
{
int thisMonth = dt.Month;
int thisYear = dt.Year;
string firstOfMonth = thisMonth.ToString() + "/1/" + thisYear.ToString();
return firstOfMonth;
}
and the last day of the month:
public string GetLastofMonth(DateTime dt)
{
DateTime Date2Obj = new DateTime(dt.Year, dt.Month, 1);
int thisMonth = dt.Month;
int thisYear = dt.Year;
Date2Obj.AddMonths(1);
Date2Obj.AddDays(-1);
int lastDay = Date2Obj.Day;
string LastOfMonth = thisMonth + "/" + lastDay + "/" + thisYear;
return LastOfMonth;
}
So in the MasterPage (or the instance, doesn't matter) I have this SQLDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MeetingsConnectionString %>"
SelectCommand="SELECT * FROM [Events] WHERE (([EventDate] >= @EventDate) AND ([EventDate] <= @EventDate2))">
<SelectParameters>
<asp:Parameter DbType="Date" Name="EventDate" />
<asp:Parameter DbType="Date" Name="EventDate2" />
</SelectParameters>
</asp:SqlDataSource>
How do I modify the EventDate and EventDate2 parameters in the SQLDataSource to use GetFirstofMonth(DateTime.Today); and GetLastofMonth(DateTime.Today), respectively, as their values? Or is this not possible?