需要在mysql表中组合两列Date和Time,并找出与当前日期和时间的差异

时间:2014-10-08 05:04:12

标签: php mysql sql date time

实际上我需要列出距离邮件日期和时间不超过24小时的数据。

我已将邮件日期和邮件时间存储在数据库的2个不同列中。

请从我写的以下查询中提供您的有效输入,

      $CTime = strtotime(date('Y-m-d H:i:s'));
      //getting the 24 hours back time
      $Btime = $CTime - 86400;

      $listingInvoice = mysqli_query($conn, "SELECT *, (CONCAT(MailDate, MailTime)) AS MailDT FROM approved WHERE JobStatus='MailedToClient' && MailDT > '$Btime'");

1 个答案:

答案 0 :(得分:0)

请检查从不同数据库列中获取的日期和时间,并找到该值,即从当前时间开始不超过24小时。

      date_default_timezone_set('Asia/Kolkata');

      //getting the current date and time...
      $CTime = date('Y-m-d H:i:s');

      //convert to string the current date and time...
      $CSTime = strtotime(date('Y-m-d H:i:s'));

      //Minus the 86400(value of 24 Hrs in seconds) in the converted date and time string
      $BStime = $CSTime - 86400;

      //getting the value of date and time before 24 Hrs...
      $BTime = date('Y-m-d H:i:s', $BStime);

      //Now the query is...
      $reject = mysqli_query($conn, "SELECT * FROM approved WHERE JobStatus='MailToClient' && MailDateTime BETWEEN '$BTime' AND '$CTime'");
      $row = mysqli_num_rows($reject);
      if ($row == '0')
      {
        echo "No Jobs Mails SENT for the Last 24 Hrs";
      }
      else
      {
        ....
      }