Timestamp to date error

Archived from the Xataface Users forum.

Petrus — Fri May 18, 2012 7:13 am

Hi to all, second question today…..
I have to convert a timestamp column to date (format d-m-Y H:i:s).

I used the delegate class and the script works but… instead to display 2012 it displays 2038!
This is the code:

Code: Select all
class tables_pagine {     function ts__display(&$record){         $ts = (int)$record->strval('ts');         return date('d-m-Y H:i:s', $ts);     } }

This is what stored in the mysql timestamp column:

Code: Select all
2012-05-18 13:41:18

… And this is the result in the view:

Code: Select all
19-01-2038 04:14:07

I tried without forcing the cast and the result in the view is:

Code: Select all
10-07-1925 02:52:38

This is the environment:
PHP: 5.3.8
Mysql: 5.5.16

Hoping someone of you can help.


camt — Fri May 18, 2012 7:52 am

http://www.php.net/manual/en/function.strftime.php

Hope that helps,

Cam


shannah — Fri May 18, 2012 9:31 am

Date fields are stored as arrays in Xataface. Use the strval() method instead of val() to make sure you’re getting it in string form. Then use the strtotime function as camt suggests.

e.g.

Code: Select all
$ts = strtotime($record->strval('ts'));

-Steve


shannah — Fri May 18, 2012 9:44 am

Whoops.. I see you were already using strval().