dongpa6867 2014-05-01 10:38
浏览 27
已采纳

PHP日期返回到下一个星期一的错误天数

Im trying to calculate number of days left to next monday and it returns 10, Im sure its wrong, days left to next monday is 5, what im doing wrong?

 if (isset($_POST['entry'])) {


  $email=mysql_real_escape_string($_POST['email']);
  $t_shirt=mysql_real_escape_string($_POST['t-shirt']);
  $today = date("m.d.Y");
  $next_monday = date("d, m, Y", strtotime('next monday'));
  $last_monday = date("d, m, Y", strtotime('last monday'));
  $today = date("d.m.Y");


  $select_current=mysql_query("SELECT * FROM entry_form WHERE email='$email'");
   if (mysql_num_rows($select_current) >= 1) {
   while ($row=mysql_fetch_array($select_current)) {

    $last_registered=$row['registered'];

    } 

    $diff = abs(strtotime($last_registered) - strtotime($last_monday));
    $years = floor($diff / (365*60*60*24));
    $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
    $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

    echo "$days";

     }
  • 写回答

3条回答 默认 最新

  • doubianxian6557 2014-05-01 10:51
    关注

    You making it to difficult for your self, already asked that question on calculating date_diff:

     //get today's timestamp
     $date_now = date_create("today");
    
     //get next monday date
     $mon_date = date_create("next monday");
    
     //calculate date difference
     $difference = date_diff($mon_date,$date_now);
    
     $int = intval($difference->format('%a'));
     echo $int;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀