Hi. I am working on an app where staff holidays run from 01 August current year - July 31st following year.
I have a gridview which display all their booked holidays and a total of days booked in the footer. I am using the paramters below to pass into my SQL query
DateTime startdate = new DateTime(DateTime.Now.Year , 08, 01);
DateTime enddate = new DateTime(DateTime.Now.Year, 07, 31).AddYears(1);
But of course as soon as we pass midnight at new year that will not work so I need some conditional check, but how to do it?. I was thinking somthing like the below might work? but I am sure there is a much better way.
DateTime NewYear = new DateTime(DateTime.Now.Year , 01, 01)
if (datetime.now >= newyear)
{
years should be reversed i.e startdate = addyears(-1) end date = Datetime.now.year
}
else
{
no change needed
}
Loading
Abhishek JainPosted Sep 3, 2013, 11:28 AM
You have to make checks anyhow, what i suggest is instead of making checks on the date after creating new year date, you can do like this:
In your case we know that the Period will start from 1st August and end on 31st July, so we can make check only on the month instead of what you have done in your example:
DateTime endDate;
int startMonth = 8;
int startMonth = 7;
{
endDate = new DateTime(DateTime.Today.Year, endMonth, 31);
else
{
}
You can try this, but yes the result is same, what i am suggesting here is that instead of creating a new year date just make a check on the current Month, that is all we need to check actually.
Regards
AJ
Stuart FraserPosted Sep 4, 2013, 3:04 AM
Stuart