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

[Solved] Ajax Date Format

2 Answers 160 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.
Gabe
Top achievements
Rank 1
Gabe asked on 19 May 2011, 06:11 PM
I am trying to apply a format to a date so if the Date == DateTime.Min basically I don't want to show anything, just blank or 'nbsp;'.
This worked with my client side databinding but now that I have added AJAX  binding it doesn't seem to work with it. It ends up showing NaN/NaN/NaN

Here is my column:

columns.Bound(o => o.MyDate).Title("My Date").Width("15%").ClientTemplate("<#= formatDateTime(MyDate) #>");


And the function:
function formatDateTime(value) {
 
    var date = (Object.prototype.toString.call(value) === '[object Date]') ? new Date(value) : new Date(parseInt(value.substr(6))); // json type
    
    var curr_date = date.getDate();
 
    if (curr_date < 10)
        curr_date = '0' + curr_date;
 
    var curr_month = date.getMonth();
    curr_month++;
 
    if (curr_month < 10)
        curr_month = '0' + curr_month;
 
    var curr_year = date.getFullYear();
 
    var datestring = curr_month + "/" + curr_date + "/" + curr_year;
 
    if (curr_year <= 1)
        datestring = '&nbsp';
 
    return datestring;
}

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 20 May 2011, 07:23 AM
Hello Gabe,

Have you tried debugging this code? What happens inside the method?

Regards,

Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Gabe
Top achievements
Rank 1
answered on 20 May 2011, 03:05 PM
It was a mistake on my part, I was  trying to create a new Date obj from an object that was already of type Date.
I change the first if condition and it worked.

var date = (Object.prototype.toString.call(value) === '[object Date]') ? value : new Date(parseInt(value.substr(6))); // json type


Thanks!


Tags
Grid
Asked by
Gabe
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gabe
Top achievements
Rank 1
Share this question
or