Formatting a MySQL timestamp field

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

Formatting a MySQL timestamp field

Postby discostrings » Tue Jan 17, 2012 1:51 pm

I've just started my first project using Xataface, and so far I'm very impressed!

I have a quick question about formatting dates. I'm sure this should be possible and easy, but I haven't found the correct way to do it even after some rather extensive searching.

If I use a DATETIME field, dates appear in list view like "2012-01-17 13:04:03". But if I use a TIMESTAMP field, which I need to do, they appear like "20120117130403". I need to have the time display formatting that is applied to DATETIME fields also apply to the TIMESTAMP field.

I tried using date_format in fields.ini with no luck.

Is there a correct way to do this?

Thanks!
discostrings
 
Posts: 3
Joined: Tue Jan 17, 2012 1:35 pm

Re: Formatting a MySQL timestamp field

Postby shannah » Tue Jan 17, 2012 2:15 pm

It should handle Timestamp the same way it handles datetime. What version are you using? Can you post the relevant portions of the table structure (e.g. the create table statement) so I can take a look. It sounds like it is just treating it like a normal varchar field.

A workaround is always to define your own fieldname__display() method in the delegate class that formats the value exactly the way you want.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Formatting a MySQL timestamp field

Postby discostrings » Tue Jan 17, 2012 4:20 pm

shannah wrote:It should handle Timestamp the same way it handles datetime. What version are you using? Can you post the relevant portions of the table structure (e.g. the create table statement) so I can take a look. It sounds like it is just treating it like a normal varchar field.

A workaround is always to define your own fieldname__display() method in the delegate class that formats the value exactly the way you want.


Thanks Steve for your quick reply--fieldname__display() worked wonderfully.

If you'd like to see whether it's a Xataface issue, my version is 1.3rc6 and the create statement is:

Code: Select all
CREATE TABLE `testtable` (
  `id` int(16) NOT NULL auto_increment,
  `created` timestamp NOT NULL default CURRENT_TIMESTAMP,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;


I can confirm that every time I try a TIMESTAMP field it displays a string with just numbers. Perhaps the problem is because my version of MySQL is quite dated--5.0.92.

Thanks again--I really enjoy this tool and I'll be around.
discostrings
 
Posts: 3
Joined: Tue Jan 17, 2012 1:35 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 12 guests

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