KendoUI formatting date and time field

28,590

Solution 1

You must use a template '#= kendo.toString(kendo.parseDate(dateCreated), 'MM/dd/yyyy HH:mm tt')#'

Solution 2

Where are you trying to use this data? If you're using it in a grid, you can use the 'template' property in the column definition

var columnDefinition = [
    {
        field: "dateCreated",
        title: "Created",
        template: "#= kendo.toString(dateCreated,'MM/dd/yyyy HH:mm tt') #"
    }
];

Here's a fiddle with the formatting in a grid

Share:
28,590
imperium2335
Author by

imperium2335

PHP, JS, MySQL coder and retired 3D modeler.

Updated on July 26, 2022

Comments

  • imperium2335
    imperium2335 almost 2 years

    I am trying to turn a previously date only field to a date-time field but it is not working.

    I have:

    schema: {
        model: {
        id: 'id',
        fields: {
            dateCreated: {
            type: "date", format: "{0:yyyy/MM/dd HH:mm}", editable: "false"
            },
            ...
        }
    }
    

    But this doesn't work, the date comes out formatted properly but the time ends up being 00:00.

    If I change the field type to "string" the data shows properly but is formatted the SQL way i.e:

    2012-05-11 12:56:29
    

    There is no such field type as "datetime", only "date". How do I get this to output how I want? i.e:

    11/05/2012 12:56
    

    Any one have any ideas?

  • imperium2335
    imperium2335 over 11 years
    I tried that but it didn't work :( I ended up preformatting my date in the SQL that brought the date out using DATE_FORMAT.