Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two dates without years in php? [duplicate]

Tags:

php

I would like to compare the two dates ,one date is which the 02 aug 1921 , and the second date is present date.How to compare the old date and present date day and month .if the past date 02 sept and present date 02 sept equals it should echo. I had the script which compares the past and present date with the year.How to compare without the year.?

$r1=$row['dateofcon']; 

//dateofcon was 02 aug 1921.

echo $r1; ?>
$cmg1 = strtotime("$r1");
$day1=date('l',$cmg1);
$now1 = time();
$timeleft1 = $cmg1-$now1;
$daysleft1 = round((($timeleft1/24)/60)/60); //probably...
if($daysleft1 == 0) { 
echo "Happy Conday";}
like image 470
ADHI Avatar asked Jan 28 '26 11:01

ADHI


1 Answers

Probably the most straight forward way is strtotime and date.

$date1 = '1 Aug 2012';
$date2 = '1 Aug 1912';
if (date('m-d', strtotime($date1)) === date('m-d', strtotime($date2)) {

}
like image 120
Corbin Avatar answered Jan 30 '26 23:01

Corbin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!