Console.WriteLine("Start Date: {0}", DateTime.Now.Date);
Console.WriteLine("End Date: {0}", DateTime.Now.AddDays(1).Date.AddMilliseconds(-1));
This would output:
Start Date: 4/30/2009 12:00:00 AM
End Date: 4/30/2009 11:59:59 PM
Let's say in NHibernate we want a criteria expression to retrieve all objects with a DateTime that falls within an entire date (regardless of time)
return Session.CreateCriteria(typeof(Person))
.Add(Expression.Between("DateOfBirth", dateOfBirth.Date, dateOfBirth.AddDays(1).Date.AddMilliseconds(-1)))
.List< Person >();
This would return all People that were born on the same day (regardless of the time of birth) since the Time portion of the Date are usually stored in the database.
2 comments:
go PHP for making things a lot more simple. lol
good stuff, this saved me a headache!
Post a Comment