date validation

1

I'm creating a validation class and I have a method to validate dates. When I am going to validate based on now , strtotime calculates including hour.

$v->rule( '07/28/2014' , 'before.2014' ) this rule only validates the year
$v->rule( '07/28/2014' , 'before.now' ) this rule validates the date M.D.Y

For the 1st case the comparison is:% strtotime( '2014' ) < strtotime( '2014' )

For the 2nd case the comparison is:% strtotime( '07/28/2014' ) < strtotime( '07/28/2014 17:59:46' )

The result is false and true . I should add H:i:s when comparing 07/28/2014, or use strtotime( date( 'm/d/Y' ) ) or other alternative to now .

In PHP you have the warning, about now , but here the time is normal

  

In PHP 5 higher than 5.0.2, "now" and other relative times are erroneously computed for midnight of the day. Unlike other versions where it is correctly computed from the current time.

    
asked by anonymous 28.07.2014 / 23:15

1 answer

1

A good option is to use the 'DateTime' object of php link

Example

$date = DateTime::createFromFormat('d/m/Y', '28/07/2014');

Note: This function is present from version 5.3 of PHP

Remember that when you omit the time it takes the current time

    
29.07.2014 / 01:55