在php ex中仅比较日期和月份而无年份。生日 [英] Compare only day and month without year in php ex. birth date

查看:62
本文介绍了在php ex中仅比较日期和月份而无年份。生日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想将当前日期的日期和月份与订阅日期的日期和月份进行比较。
ex。当前日期(dm)= 3-6 ,我想将其与任何其他 dm

进行比较在php
中,在我的项目条件中,就像我们不比较年份的出生日期。

I want to compare current date's day and month with subscription date's day and month only. ex.current date(d-m) = 3-6 and I want compare it with any other d-m
How should i do it in php In my project condition is like birth date in which we don't compare year.

请帮帮我。
预先感谢。

Please help me out. Thanks in advance.

推荐答案

其中的窍门是让月份优先。这样,PHP可以按最大值比较数字。看下面的示例:

The trick in this is to let the month come first. This way PHP can compare the numbers by highest value. Take a look at the following example:

$aDate = DateTime::createFromFormat('m-d', '05-20');
$bDate = DateTime::createFromFormat('m-d', '06-29');

if ($aDate->format('md') > $bDate->format('md')) {
    echo "'aDate' is bigger than 'bDate'";
}

这篇关于在php ex中仅比较日期和月份而无年份。生日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆