Datepicker & timestamps

I want to use a datepicker on a form, but in the background, store a timestamp in the database.

The user (via the web page) should only ever see a nicely formatted date.

Any suggestions on how to achieve this ?

Leon

You can override the beforeSave() and afterFind() methods in your model. Also: Check if the DATETIME field type doesn’t suit your needs better.

Thanks for the suggestion, I thought that may be the case.

DATETIME field could be an option, but I would still have to do some data processing since mySQL stores in an american format, rather than the more commonly used format in the UK.

Are you going to deploy on a single-purpose box? The date format can be changed within MySQL. I have to admit, that’s a bit of an overkill, though :lol: The change to a DATETIME field can yield many benefits, btw: There are some nifty things MySQL can do with that.

Anyway: If you need this more than once, write a behaviour catching up on the beforeSave() and afterFind() handlers. Saves you a significant amount of both, time and sanity ;)

Can you provide more info on what you mean by this ?

I’m fairly new to it ;)

Thanks, Leon

Just have a look at what the CTimestampBehavior does. It is close to what you need. You might want to check the Yii Guide’s section on behaviours as well.