I have an activity that only perform in a date range regardless month/year. I need to validate if the current date is >= 30 and <= 05 (next month).
Sample code below:
$t = microtime(true);
$micro = sprintf("%06d",($t - floor($t)) * 1000000);
$d = new DateTime( date('Y-m-d H:i:s.'.$micro, $t) );
$date = substr($d->format("d"),0,2);
if($date >= 30000000 && $date <= 05000000){
$validate = true;
}
I simply cannot use >= 30 and <= 05 as it is an invalid range. Or should I need to code:
if($date = 30 || $date = 31 || $date = 01 || $date = 02 || $date = 03 || $date = 04 || $date = 05){
$validate = true;
}
Yeah, I think your code is ok. You could do by using timestamps I guess, but a little improvement for your code could be:
$dates = array(30, 31, 1, 2, 3, 4, 5);
if (in_array(((int)$date), $dates)
$validate = true;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments