views:

34

answers:

1

This is regarding Symfony 1.4, and probably all prior versions, running php 5.3, mysql 5.1.

If I store old dates in a database < 1970..., and I then retrieve them, they are automatically converted into an incorrect date.

Example table:

id, some_date
1, 1961-09-09

A quick example.

$record = MyTablePeer::retrieveByPK(1);
echo $record->getSomeDate(); 
//returns: 09/09/61
//Want it to return: 1961-09-09

Where is the output format controlled from? I need to get the entire date with the entire year stored in the database.

+3  A: 

Date field getters have a $format parameter, use that, like $record->getSomeDate("Y-m-d");.

Also, this is what the docblock says about date accessors:

This accessor only only work with unix epoch dates. Consider building with propel.useDateTimeClass or change this column type to the (deprecated) "before-unix" column type (e.g. BU_TIMESTAMP or BU_DATE) if you need to support pre-/post-epoch dates.

@param      string $format The date/time format string (either date()-style or strftime()-style).
             If format is NULL, then the integer unix timestamp will be returned. 
@return     mixed Formatted date/time value as string or (integer) unix timestamp (if format is NULL).

@throws     PropelException - if unable to convert the date/time to timestamp.
Maerlyn