ASCII码 ASCII码

php 判断当前日期是否是每个月的第一天

发布于:2022-02-19 18:40:49  栏目:技术文档
  1. <?php
  2. function getthemonth($date)
  3. {
  4. $firstday = date('Y-m-01', strtotime($date));
  5. $nowday = date('Y-m-d', strtotime($date));
  6. $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
  7. return array($firstday,$nowday,$lastday);
  8. }
  9. $today = date("Y-m-d");
  10. $day=getthemonth($today);
  11. echo "当月的第一天: ".$day[0]." 当天日期: ".$day[1]." 当月的最后一天: ".$day[2];
  12. echo "<br/>";
  13. if($day[0] == $day[1]){
  14. echo '今天的日期是当月的第一天';
  15. }else{
  16. $num = explode('-',$day[1]);
  17. echo '今天的日期不是当月的第一天,而是第'.$num[2].'天';
  18. }
  19. ?>
相关推荐
阅读 +