Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting propel by default to date format getDate("Y-m-d"), to work better with zend toArray()

My query returns an object that has a date field

$obj = ObjectQuery::create()->findPK(11);
  • var_dump($obj) shows me the date field as yyyy-mm-dd like it is in the database
  • $obj->getThedate(); changes the format to mm/dd/yy which I don't want to happen
  • $obj->getThedate("Y-m-d"); gives me same format in the database yyyy-mm-dd

So to get the data in the same format it's stored in the database, I need to set the format when I'm getting that specific date field, like the third line.

The problem is that I'm not reading the date field separately. I'm taking the full $obj as a whole and turning it into an array using Zend's toArray(), so I don't have control over how toArray() reads the date field. Is there a way to set Propel to deliver in the format ("Y-m-d") as a default? Something maybe in the prople config settings?

like image 361
jblue Avatar asked Jan 20 '23 10:01

jblue


1 Answers

The default format Propel uses for temporal columns can be configured by three build configuration parameters:

propel.defaultTimeStampFormat = {Y-m-d H:i:s}|string
propel.defaultTimeFormat = {%X}|string
propel.defaultDateFormat = {%x}|string

As you can see, the default format for dates is %x, which is the preferred date representation based on your locale. You should change it to %Y-%m-%d or the shorthand %F.

like image 169
Jan Fabry Avatar answered Jan 30 '23 13:01

Jan Fabry