Timestamp to date error

A place for users and developers of the Xataface to discuss and receive support.

Timestamp to date error

Postby 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. :roll:
Petrus
 
Posts: 1
Joined: Fri May 18, 2012 1:30 am

Re: Timestamp to date error

Postby camt » Fri May 18, 2012 7:52 am

camt
 
Posts: 17
Joined: Wed Jan 04, 2012 9:28 am

Re: Timestamp to date error

Postby 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
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Timestamp to date error

Postby shannah » Fri May 18, 2012 9:44 am

Whoops.. I see you were already using strval().
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved