Datefield Format Confusion

Datefield Format Confusion

ITDATAGITDATAG Posts: 18Questions: 6Answers: 1

Hello All,

I am all confused with a date field usage in editor.

this is the original date field specification on the editor declaration:

                label: "Activity Date:",
                    name: "ActDate",
                type: "datetime",
                    def: function () { return new Date(); }

datatable declaration:

    columnDefs: [
               // { targets: 1, render: $.fn.dataTable.render.moment('Do MMM YYYY') },
                { targets: 1, render: function (data) { return moment(data).format('MM-DD-YYYY') } }
            ],

controller declaration (.Net Package)

                      .Field(new Field("ActDate")
                        .Validator(Validation.DateFormat(
                            Format.DATE_ISO_8601,
                            new ValidationOpts { Message = "Please enter a date in the format yyyy-dd-MM" }
                        ))
                       .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601))
                       .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
                )

Then I added the format to the editor as below:
label: "Activity Date:",
name: "ActDate",
type: "datetime",
def: function () { return new Date(); },
format:"MM-DD-YYYY"
Results was the same:

another format:
label: "Activity Date:",
name: "ActDate",
type: "datetime",
def: function () { return new Date(); },
format:"yyyy-dd-mm"
same results

Can anyone Please share any information they may have.. ?
FYI, I tried other format on the set and get and then I could not validate.

my preference would be to show on the "MM-DD-YYYY"

thanks

This question has an accepted answers - jump to answer

Answers

  • ITDATAGITDATAG Posts: 18Questions: 6Answers: 1

    I will try to clarify a bit with More information..

    One instance shows properly formatted when adding a new record. But looses the format on edit?

    Editor new looks formatted properly:

    When I try update the format has changed?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @ITDATAG ,

    This example here may be useful - it's creating a new date. Similarly, this one here.

    Hope that helps,

    Cheers,

    Colin

  • ITDATAGITDATAG Posts: 18Questions: 6Answers: 1

    Hello Colin , thank you for taking the time to answer.

    I have been working with the example you pointed out from the beginning. I am not sure what I have done wrong I am going over each line as it odd that it only display the wrong format. When in editing mode.

    thanks
    btw I am using the this as formats

        .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601))
        .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
    
  • ITDATAGITDATAG Posts: 18Questions: 6Answers: 1
    Answer ✓

    Colin,

    Thanks for your answer I found the issue. I had a model that being recreated and the field was being set per database type as datetime. I have updated and it work

    In case anyone runs into this issue ensure your dates field are set to string and not datetime type.

    thanks

This discussion has been closed.