![]() |
HI ,
can i validate date with grater than ? this is my validation : Code: 'data_tour' => [ and this is the validation (not passed) : Data Partenza deve essere maggiore di oggi2025-04-21|2025-04-20 2025-04-21 is bigger than 2025-04-20...
Convert your date into a unix timestamp after validating it once as a valid date and then perform the greater_than validation. Alternatively, you could pass your dates in a specific format 'Ymd' and the comparison would work.
I create a custom rules:
Code: <?php solved
04-20-2025, 08:59 PM
(This post was last modified: 04-22-2025, 11:19 PM by InsiteFX. Edit Reason: Fixed missing $ sign ) PHP Code: // PHP Method to compare dates What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
@pippuccio76 : You do not need to return the booleans true or false, you can return $date_to_control > $today which evaluates to a boolean.
@InsiteFX :Your code is erroneous InsiteFX. The second parameter of the function doesn't have a $ in front of date2, $date1 > $date2 performs a string comparison not a date comparison and finally applying the ->format method to a string throws a fatal exception. This code is exceedingly error prone. As an aside, whenever you're comparing dates you should use the DateTimeImmutable class rather than DateTime.
Wasn.t my code I got it off the web to show him another way of doing it.
Thank you for pointing the error out. All fixed now. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |