I have a telerik grid in which i have a column where i show DateOfBirth of the user. Below is the partial code of my Telerik Grid column:
columns.Bound(c => c.DOB).Title("DateofBirth").Format("{0:MM/dd/yyyy}");
As i have to display on date part on UI i am returning .Date from the model as shown below:
public DateTime? DOB
{
get
{
if (DateOfBirth > DateTime.MinValue)
return DateOfBirth.Date;
else
return null;
}
}
Where DateOfBirth is the date which i get from Database which has Date and Time format. The issue is i see the date off by one day in some scenarios and not always. what could be the cause of that?
For example if the date returned from DB is 06/21/2012 12:00:00 PM then i am getting it as 06/20/2012
It might have to do with the culture-specific datetime.
Are you using different cultures. For example I have ran into scenarios where the database is a universal time and I had to parse the date to get my specific culture.
A few hours change end up changing the date to one day different.
Here is example usage:
http://msdn.microsoft.com/en-us/library/ey1cdcx8
Code Example:
or System.Globalization.DateTimeStyles.AssumeLocal to get to local.