Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I have a column in gridview in which I will display DateTime value being retrieved from database. I am using MVC and when the datetime value being passed through javascript, the space between date and time is getting replaced with an extra "T" character. I wish to remove this "T" and have the space back in between. Below are my codes in javascript:

$.ajax({
    async: false,
    type: "POST",
    url: "/Calendar/GetDateStart",
            }).success(function (data) {
                grid = $('#gdNotificationInformation').kendoUIGrid($.extend({
                    },
                    dataSource: {
                        data: data.data,
                    },
                    columns: [
                        { field: "a1", title: "Date Start", headerAttributes: { style: "overflow: visible; white-space: normal" } },
}],
}));
});



I am just showing the partial codes as this is the only codes segment that is having problem. Any help would be appreciated. Thank you.

What I have tried:

1. Convert the datetime value into string in Controller before pass it into javascript but no avail.
Posted
Updated 11-Oct-17 23:01pm
v3
Comments
Karthik_Mahalingam 12-Oct-17 5:00am    
check this
https://stackoverflow.com/a/27961034/1147428
Jamie888 12-Oct-17 5:03am    
Sir, I have checked my controller. The value is indeed in datetime format without "T"
Karthik_Mahalingam 12-Oct-17 5:08am    
can you post the datetime value which you are getting in controller
Jamie888 12-Oct-17 5:13am    
It is in this format sir:
10/11/2017 7:42:16 AM DataType is DateTime
Karthik_Mahalingam 12-Oct-17 5:23am    
then the problem is in UI

1 solution

The chances are that it isn't: you need to check two things.
1) Look at the raw data in your DB: is it in a DATETIME or DATETIME2 column? If it isn't, that's your problem: its string based, and that a very bad idea. Change your database design so you store all data in appropriate data types. Anything else will give you more trouble than you can believe in the long term.
2) If it's a date format column, then the problem is the formatting applied to the gridview by the browser, or to the data by your code after it has been extracted from the database. Start by following the data through your system from the point of retrieval, and watch what happens to it: at some point it will be formated for the display and that's where the problem is happening.
 
Share this answer
 
Comments
Jamie888 12-Oct-17 4:57am    
Sir, the data type I am using in database is DATETIME2. I have put a break point at the last line before it is entering javascript and the datetime value is still without "T". Only when it getting display it is showing the "T".
OriginalGriff 12-Oct-17 5:03am    
Right: so the formatting is being applied by the browser, and you can't "just remove it" you need to look at the cell / column formatting to find out what is being applied. If there is no such formatting, then it's being rendered in the default datetime format for the client PC - which means it's either exactly what the user has asked for, or you need to override the default formatting. Do the last with care: remember that the internet is by it's nature international, and "fixing" a date format can have nasty repercussions for some users!
Jamie888 12-Oct-17 5:02am    
I have updated the question to better reflect the scenario here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900