Format::dateTime with Unix timestamp

Format::dateTime with Unix timestamp

aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

I have 3 timestamp field in my data. The first and third are set as read only in editor as I don't want the users to be able to edit those. The second is set as a date field.

I'm using the following code in order to format the date from 'U' to 'd-m-Y' but the JSON is showing null values returned.

Field::inst('Audits.Date_created')
  ->getFormatter(Format::dateTime('U', 'd-m-Y')),
Field::inst('Audits.Date_requested')
  ->getFormatter(Format::dateTime('U', 'd-m-Y'))
  ->setFormatter(Format::dateTime('d-m-Y', 'U')),
Field::inst('Audits.Date_completed')
  ->getFormatter(Format::dateTime('U', 'd-m-Y')),

Here is an excerpt from the JSON response.

{"data":[{
    "DT_RowId":"row_3",
    "Audits":{
        "id":"3",
        "Customer_id":"1",
        "Location_id":"1",
        "Date_created":null,
        "Date_requested":null,
        "Date_completed":null,
        .........

Can anyone see what I am doing wrong?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    That looks OK. Could you give some examples of the date formats, please, as that may give some clues,

    Colin

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    the database is storing a Unix timestamp so the getformatter will be receiving a timestamp and should be converting it to 'd-m-Y'

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Could you show me your database schema please? Also what does your database return if you do a simple SELECT Date_created FROM AUDITS; please?

    Allan

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    ok thanks Allan.

    You put me on the right track again.

    I wasn't aware MySQL no long stored timestamp fields as a Unix timestamp. They are now stored in "Y-m-d H:i:s" format instead.

This discussion has been closed.