Matthew Machuga Thu Jan 06 12:12:18 -0500 2011

Subject: Date validates_format_of issue

I've tried on both the stable and nightly build, but I can't seem to correctly utilize validates_by_format on a date field. Is there a certain way I need to reference this since any date is a datetime object?

My validator is:

static $validates_format_of = array(
        array('my_date', 'with' => '/[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}/')
);

Any recommendations or info?


Jacques Fuentes Thu Jan 06 21:30:59 -0500 2011

Well, since it's a DateTime object, you can format it however you want. Also, PHP-AR automatically formats the date as you'd like when inserting into the database by using the specified default date format found here: http://www.phpactiverecord.org/docs/ActiveRecord/DateTime#var$DEFAULT_FORMAT

Matthew Machuga Fri Jan 07 16:09:14 -0500 2011

Jacques,

Right; I think I poorly explained that. I'd like to validate that it matches that format prior to being made into a DateTime object so it doesn't try to transform text into a DateTime object, causing an exception. It looks like it may not be possible as it stands?

(1-2/2)