if have 2 dates, 21/05/2010 , 23/05/2010, how can find out if 22/05/2006 7:16 am exists in between them?
i using following code calculate min/max date , select records in table clear update them.
$today = date('l'); if($today == 'wednesday'){ $min = date('d/m/y', strtotime('0 days')); $max = date('d/m/y', strtotime('+6 days')); }else if($today == 'thursday'){ $min = date('d/m/y', strtotime('-1 days')); $max = date('d/m/y', strtotime('+5 days')); }else if($today == 'friday'){ $min = date('d/m/y', strtotime('-2 days')); $max = date('d/m/y', strtotime('+4 days')); }else if($today == 'saturday'){ $min = date('d/m/y', strtotime('-3 days')); $max = date('d/m/y', strtotime('+3 days')); }else if($today == 'sunday'){ $min = date('d/m/y', strtotime('-4 days')); $max = date('d/m/y', strtotime('+2 days')); }else if($today == 'monday'){ $min = date('d/m/y', strtotime('-5 days')); $max = date('d/m/y', strtotime('+1 days')); }else if($today == 'tuesday'){ $min = date('d/m/y', strtotime('-6 days')); $max = date('d/m/y', strtotime('0 days')); }
datetime::diff
create datetime::diff between 21/05/2010 , 22/05/2006 7:16 am, datetime::diff between 23/05/2010 , 22/05/2006 7:16 am.
then check first datetime::diff > 0
, , second < 0
update : used datetime::createfromformat, php5.3 method
update2 : tested code sample. produces expected output.
<?php $datetime_lower = datetime::createfromformat('d/m/y', '21/05/2010'); $datetime_upper = datetime::createfromformat('d/m/y', '23/05/2010'); $datetime_compare = datetime::createfromformat('d/m/y g:i a', '22/05/2006 7:16 am'); var_dump($datetime_lower < $datetime_compare); var_dump($datetime_upper > $datetime_compare); if ($datetime_lower < $datetime_compare && $datetime_upper > $datetime_compare) { echo " + date between"; } else { echo " date not between"; }
also, there procedural date_diff function
Comments
Post a Comment