This is a migrated thread and some comments may be shown as answers.

[Solved] telerik grid not showing proper date

5 Answers 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mandar Bansod
Top achievements
Rank 1
Mandar Bansod asked on 18 Sep 2012, 07:03 AM
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?

here is my javascript function

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;
    }

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.

5 Answers, 1 is accepted

Sort by
0
Pedro
Top achievements
Rank 2
answered on 20 Sep 2012, 06:29 PM
Did you try using

.Format("{0:d}")

?
0
Carl
Top achievements
Rank 1
answered on 22 Oct 2012, 02:18 PM
I'm having the same issue and I've narrowed it down to a timezone issue.

Users in EST (same time zone as the database and web servers) see the correct time.

Users in PST see the dates as -1 day from what it should be.   i.e. 7/30/2012 shows as 7/29/2012.  It also breaks the filtering.  You can't filter on the displayed date or the correct date.  Always returns no results.

Has anyone figured out what this is yet?
I've tried both formats below with the same results

columns.Bound(e => e.Due_Date).Width(20).Title("Due Date").Format("{0:d}");
 
columns.Bound(e => e.Due_Date).Width(20).Title("Due Date").Format("{0:mm/dd/yyyy}");
0
Denis
Top achievements
Rank 1
answered on 14 Nov 2012, 03:54 PM
the same issue. any solutions or fixes for that?
0
Murillo
Top achievements
Rank 1
answered on 22 Nov 2012, 05:21 PM
I have same problem. Solution, Telerik Team?
0
Carl
Top achievements
Rank 1
answered on 26 Nov 2012, 01:23 PM
It appears that there is or will be no solution offered by Telerik based on several other conversations I have followed.

I ended up switching to a string value so it would take the value exactly as it's presented.  The downside is that I loose the datepicker filter, but it at least leaves the date unmolested.

It is supposedly a browser or client side conversion, not an actual code issue.

HOWEVER

Since I've seen others post attempted code work arounds, it would seem that Telerik could roll something like that into Kendo (if it's not already there since we haven't moved to Kendo) and add a property to the grid to allow you to adjust or not as you see fit.
Tags
Grid
Asked by
Mandar Bansod
Top achievements
Rank 1
Answers by
Pedro
Top achievements
Rank 2
Carl
Top achievements
Rank 1
Denis
Top achievements
Rank 1
Murillo
Top achievements
Rank 1
Share this question
or