Format::dateTime with Unix timestamp
Format::dateTime with Unix timestamp
aarontharker
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
This discussion has been closed.
Answers
That looks OK. Could you give some examples of the date formats, please, as that may give some clues,
Colin
the database is storing a Unix timestamp so the getformatter will be receiving a timestamp and should be converting it to 'd-m-Y'
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
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.