Date and Time formats

Date and Time formats

prema770prema770 Posts: 37Questions: 11Answers: 0
edited September 2018 in Free community support

I'm new to this and wondering if anyone can point me in the right direction around date formats. I'm a registered user of the editor - the combination of the editor and grid has been an amazing experience

The set up involves
* A standard MySQL
* A generator instance against a simple booking table

On the automatically generated js file, there is a formatting option for date time fields

            {
                "label": "Departure date \/ time:",
                "name": "departureDateTime",
                "type": "datetime",
                "format": "ddd D MMM gggg h:mm A"  <-- Does this fomat the field / the widget?
            },

On the PHP Side

    Field::inst('departurePickupTime')
        ->validator(Validate::dateFormat('H:i A'))
    ->getFormatter(Format::datetime('H:i:s', 'H:iA'))
        ->setFormatter(Format::datetime('H:i A', 'H:i:s')),

The goal is to get a Mon 14 Jul 2018 08:12pm format on the grid and in the form thing
Can anyone please point me at information on the roles of the

  • JS Validation
  • The get and set formatters
  • PHP Validation

Have already read the docs several times over
Thanks for any tips :-)

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    The idea here is that the client-side should see only one format (and submit that same format). So the get and set formatters are used to convert it:

    ->validator(Validate::dateFormat('D j M Y h:iA'))
    ->getFormatter(Format::datetime('Y-m-d H:i:s', 'D j M Y h:iA'))
    ->setFormatter(Format::datetime('D j M Y h:iA', 'Y-m-d H:i:s'),
    

    would be what you want on the server-side. e.g. on "get" convert from ISO8601 to D j M Y h:iA (see the PHP docs for that). Then the reverse for the set formatter and use the appropriate validator.

    Allan

  • prema770prema770 Posts: 37Questions: 11Answers: 0

    Excellent - thanks very much. Really appreciate the response

This discussion has been closed.