wordpress - PHP check if the dates are in current week -
i using wordpress cms. trying check if of user has birthday in current week. no success.
here code
$fd = date("y-m-d",strtotime('monday week')); $ld = date("y-m-d",strtotime("sunday week")); $cdate = date('m-d',time()); if (($cdate >= $fd) && ($cdate <= $ld)) { echo 'true'; } else { echo 'false'; } this returning false me if use
'm-d' in $cdate variable it works fine if use y-m-d in case , years should same isnt possible people have different birth years
here's way
to find can this
step 1 :
find start , last day of week
$firstday = date("y-m-d", strtotime('sunday last week')); $lastday = date("y-m-d", strtotime('sunday week')); step 2 :
see if given date between start , last day of week
if($date > $firstday && $date < $lastday) { echo "it between"; } else { echo "no not !!!"; } if
yesbelongs elsenot
so, code shall have
<?php $date = "2015-06-01"; #your own date $date = date(y-m-d); #or current date $firstday = date("y-m-d", strtotime('sunday last week')); $lastday = date("y-m-d", strtotime('sunday week')); if($date > $firstday && $date < $lastday) { echo "it between"; } else { echo "no not !!!"; } ?> note
you can have own start day i.e.,
sundayormondayyou can have own date or current date
Comments
Post a Comment