Check if date.now goes into New year
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
}