0
votes

We are using SQL Server generating some data One of the column is Date, which is defined as 'MMM d yyyy'. So, the possible values are:

Jan  1 2017
Jan 21 2017
Jan 12 2017
...

note that, there are 2 spaces in the 1st sample between 'Jan' and '1'. How can we parse this date in Kendo Grid?

kendo.parseDate seems does not support this format.

Our plan is to change the output of SQL Server, but want to see whether there are some simple way on kendo side to do this.

Thanks

1
What data type is your Date column in SQL Server? - SqlZim
In Kendo grid? Type is Date. In SQL, is VARCHAR(11) - urlreader
The best possible fix would be to stop storing dates as strings. That is why we have the date and datetime datatypes. - Sean Lange
it is not stored in SQL, it is output as VARCHAR(11) for format purpose. - urlreader
So in your SQL database, you have a record with value such as 2017-01-01, correct? You are trying to display this value in kendo grid as Jan 1 2017, correct? - ShawnOrr

1 Answers

0
votes

Been a while, but perhaps this may help

Example

kendo.parseDate(new Date("Jan  1 2017"), "MM/dd/yyyy");

In my head,

  1. It makes more sense to store dates as dates in SQL Server. Too many things can go wrong by trusting strings.
  2. It would be a small matter to convert your string in SQL Server with either convert() or if 2012+ try_convert().

Example

Declare @YourTable Table ([DateStr] varchar(50))
Insert Into @YourTable Values 
 ('Jan  1 2017')
,('Jan 21 2017')
,('Jan 12 2017')

Select *
      ,AsDate = try_convert(date,DateStr) 
 From @YourTable

Returns

DateStr       AsDate
Jan  1 2017   2017-01-01
Jan 21 2017   2017-01-21
Jan 12 2017   2017-01-12