Hi,
I am using telerik extensions for Asp.Net MVC from last 1 year.
Earlier I noticed that there is some major difference between the date at server & in Sql Server & date that is rendered in telerik column.
Attached is the screen shot showing the date difference.
Can you suggest any centralized solution to overcome this problem, because till now have grids at lot more places & this issues is burning my heads.
After some googling I found that browser usually adds some time offset of browser time zone before rendering a date in javascript, so my simple solution was to subtract that browser time zone offset from the date I am getting.
So I added a javascript function to handle this but still the solution works in one time zones but for other it shows a lot more difference.
My server is located in Central time zone whereas users are all accross other timezones in US.
Can any one suggest me any solution for this?
function parseToServerTimezone(date) {
if (date != null) {
var clientOffset = new Date().getTimezoneOffset();
var newDate = new Date(date);
newDate.setMinutes(date.getMinutes() - clientOffset);
return $.telerik.formatString("{0:g}", date);
}
return date;
}
here is my javascript function and here is how it is used in grid, all my grids are ajax bound here
mandarbansod
Member
317 Points
114 Posts
telerik mvc grid not showing proper date
Sep 18, 2012 07:14 AM|LINK
Hi,
I am using telerik extensions for Asp.Net MVC from last 1 year.
Earlier I noticed that there is some major difference between the date at server & in Sql Server & date that is rendered in telerik column.
Attached is the screen shot showing the date difference.
Can you suggest any centralized solution to overcome this problem, because till now have grids at lot more places & this issues is burning my heads.
After some googling I found that browser usually adds some time offset of browser time zone before rendering a date in javascript, so my simple solution was to subtract that browser time zone offset from the date I am getting.
So I added a javascript function to handle this but still the solution works in one time zones but for other it shows a lot more difference.
My server is located in Central time zone whereas users are all accross other timezones in US.
Can any one suggest me any solution for this?
function parseToServerTimezone(date) { if (date != null) { var clientOffset = new Date().getTimezoneOffset(); var newDate = new Date(date); newDate.setMinutes(date.getMinutes() - clientOffset); return $.telerik.formatString("{0:g}", date); } return date; }here is my javascript function
and here is how it is used in grid, all my grids are ajax bound here
column.Bound(m => m.CapCycleStartDate).Title(Html.Resource("CapCycleStartDate")).ClientTemplate("<#= parseToServerTimezone(CapCycleStartDate) #>").Width(18).HtmlAttributes(new { align = "center" });Thanks.
Regards,
Mandar Bansod
ignatandrei
All-Star
134913 Points
21619 Posts
Moderator
MVP
Re: telerik mvc grid not showing proper date
Sep 18, 2012 07:34 AM|LINK
And if you display in the Html, without telerik, it's a difference or not?
And please give an example.
mandarbansod
Member
317 Points
114 Posts
Re: telerik mvc grid not showing proper date
Sep 18, 2012 07:44 AM|LINK
Hi,
When I render the date for same record in Html as shown in attached screenshot
see the value of the Cap Cycle Start date it is the original value that I have in sql server
but when I render the same record in grid below as highlighted with yellow,
the first column shows the changed date & second shows the same date when rendered as a string.
there is a differences of 1Hr when in Central Time zone & 3 Hrs when in estern time zone etc.
Regards,
Mandar Bansod
ignatandrei
All-Star
134913 Points
21619 Posts
Moderator
MVP
Re: telerik mvc grid not showing proper date
Sep 18, 2012 09:11 AM|LINK
And the column type in Sql server is...?
mandarbansod
Member
317 Points
114 Posts
Re: telerik mvc grid not showing proper date
Sep 18, 2012 09:29 AM|LINK
date
Regards,
Mandar Bansod
Young Yang -...
All-Star
21344 Points
1818 Posts
Microsoft
Re: telerik mvc grid not showing proper date
Sep 24, 2012 09:06 AM|LINK
Since telerik is third party plugin, it is better to post this question to their forum, you may get someone's quick reply from there.
Regards
Feedback to us
Develop and promote your apps in Windows Store
mandarbansod
Member
317 Points
114 Posts
Re: telerik mvc grid not showing proper date
Sep 24, 2012 09:08 AM|LINK
Thanks for the reply.
I have already posted the same issue in telerik forum, but didn't get any reply
Regards,
Mandar Bansod
urillo
Member
2 Points
1 Post
Re: telerik mvc grid not showing proper date
Nov 22, 2012 04:27 PM|LINK
I have same problem. Found a solution?
CPrakash82
All-Star
18270 Points
2839 Posts
Re: telerik mvc grid not showing proper date
Nov 22, 2012 05:42 PM|LINK
Just specify the format here.
column.Bound(m => m.CapCycleStartDate).Format("{0:MM/dd/yyyy}").Title(