Yii Framework Forum: Database date format - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Database date format Converting to/from database format Rate Topic: -----

#1 User is offline   nmunro 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 20-January 10

Posted 20 January 2010 - 11:18 AM

I'm looking for a clean way to convert from the database date format (in my case Oracle) to a timestamp that I can then use to display in the locale format (e.g. "01-01-2010"), edit that and then send it back to database format on save.

In CodeCharge (a RAD system) I can define a single "database date format" parameter and it automatically handles this, it would be great if a parameter be defined like:
  'db'=>array(
    'connectionString'=>'oci:dbname=//localhost/xe',
    'username'=>'user',
    'password'=>'pass',
    'dateFormat'=>'d-M-y', //using PHP date() formatting
  )


Or maybe allow SQL to be defined for DATE types so it either converts to unix timestamp or uses the app's format directly, e.g.

write: colname = (TO_DATE('19700101000000','YYYYMMDDHH24MISS')+NUMTODSINTERVAL(timestamp,'SECOND'))
read: timestamp = (colname - TO_DATE('19700101000000','YYYYMMDDHH24MISS')*86400)

or (less usefully)

write: colname = TO_DATE($date, $displayToDbDateFormat)
read: $date = TO_CHAR(colname, $dbToDisplaydateFormat)

What do you think?
0

#2 User is offline   lucifurious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 184
  • Joined: 15-March 09
  • Location:Atlanta, GA.

Posted 20 January 2010 - 11:29 AM

I found that this is best handled with a behavior.

I have written one as part of the next release of my extension library, however you can pull it from svn as it is public:

Http://code.google.c...-yii-extensions

Enjoy!
0

#3 User is offline   lucifurious 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 184
  • Joined: 15-March 09
  • Location:Atlanta, GA.

Posted 20 January 2010 - 01:10 PM

Wrong link, sorry:

http://code.google.c...yii-extensions/
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users