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

Formatting dates in custom popup editor not in a textbox

2 Answers 165 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 06 Jul 2015, 05:17 PM

I am trying to use the custom popup editor template when editing an item in my grid.  The issue I am having has to do with formatting the date to be in the "format MM/dd/yyyy" or 07/02/2015 .  Everything works fine when I am displaying a date in a textbox.  But when I display the date in a div instead, the date the same date looks like this: Thu Jul 02 2015 10:22:33 GMT-0600 (Mountain Daylight Time).

 Below is a jsfiddle link that demonstrates both the correct date in a textbox and bad date in a div, just below it.  I want the div to have the same format as the textbox.  I have followed example after example I have found, but I can't seem to get it right so that they format the date the same.  Please help! 

Attached is a screenshot indicating where the formatting is wrong and where it is formatting ok.

http://jsfiddle.net/BCBzS/912/

2 Answers, 1 is accepted

Sort by
0
Accepted
TorgueFan
Top achievements
Rank 1
answered on 06 Jul 2015, 08:58 PM
Hello Dan,

Take a look at this example. The following code will help you with formatting "BirthDate" to a desired format.

1. Click on the example.

2. Click run.

3. Click on edit.

Firstly, the format of a Kendo DatePicker is by default "MM/dd/yyyy". Here's the documentation showing 
more details on formatting.

Secondly, the "BirthDate" variable defined inside a template expression changes the formatting
from a date-time to a string.

Here is a list of standard date formats using kendo.toString(). Here is more documentation on template expressions(scroll down to the External Templates and Expressions section).

Hope this helps!
0
Dan
Top achievements
Rank 1
answered on 06 Jul 2015, 09:13 PM
That example was perfect!  All I needed was to add
#= kendo.toString((BirthDate), "d") #
 not in the js file, but also into my kendo template code.  It is working great now.  Thank you for the example.  That helped to clarify my issue.
Tags
Grid
Asked by
Dan
Top achievements
Rank 1
Answers by
TorgueFan
Top achievements
Rank 1
Dan
Top achievements
Rank 1
Share this question
or