Datatable editor DateTime format conversion

Datatable editor DateTime format conversion

PignattinoPignattino Posts: 10Questions: 2Answers: 0

I'm using formatters in my controller to set a date string format into DateTime sql data… the field is set as following in VB.net

            .Field(New Field("OrdiniGiornaliero.RitiroDopo") _
                        .GetFormatter(Format.DateSqlToFormat("dd/MM/yyyy HH:mm")) _
                        .SetFormatter(Format.DateTime("dd/MM/yyyy HH:mm"))) _

when reading data everything is correct.. display data in the format I want… when update data an error occurred

        The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated

so cannot convert string date and time to a dataTime valid format for database….

if I set the formatter with

            .SetFormatter(Format.DateFormatToSql("dd/MM/yyyy HH:mm"))) _

saves only date but not time…..

any idea?

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    Are you using a model? If so can you try using "OrdiniGiornaliero.RitiroDopo" as a string please.

    Allan

  • PignattinoPignattino Posts: 10Questions: 2Answers: 0

    It is a string

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    Actually I just saw in your e-mail on this same topic that you are using a string.

    Format.DateTime("dd/MM/yyyy HH:mm")

    The Format.DateTime method takes two parameters - a from and to (I'm slightly surprised it isn't giving a compile error if only one is passed actually). Could you give it a second parameter in the ISO8601 format please.

    Allan

  • PignattinoPignattino Posts: 10Questions: 2Answers: 0

    the second parameter is optional.. I've tried also with constant values like iso8601 (it is a constant string that posto only a date.. not with a time value...)
    if this function Format.DateTime(from, to) convert a string date format to another, what is it useful for??
    anyway.... it doesn't work :(

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    It is optional but its a little redundant since if you leave to as null then it will take the value of the from parameter.

    You need to use something like:

    Format.DateTime("dd/MM/yyyy HH:mm", "yyyy-MM-dd HH:mm:ss")
    

    Allan

  • PignattinoPignattino Posts: 10Questions: 2Answers: 0

    the thing weird is that seems to confuse months with days in the dd/MM/yyyy HH:ss format... and using format.DateTime with only one parameter...
    because if I set 12/12/2016 12:00 it works.... and if I set 02/12/2016 12:00 and I reopen the calendar, it sets February 12th........ and if I set 13/12/2016 12:00 have an error....
    This can help you?

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin

    How have you configured it on the client-side?

    Allan

  • PignattinoPignattino Posts: 10Questions: 2Answers: 0

    ok allan.. found the way!
    as you suggested...
    Format.DateTime("dd/MM/yyyy HH:mm", "yyyy-MM-dd HH:mm:ss")

    previously I didn't put seconds in "to" date... because my date doesn't have it...
    with seconds works!
    thanks!!!

This discussion has been closed.