gpt4 book ai didi

php - 如何在 PHP 中减去两个日期并在没有交互的情况下发送自动电子邮件

转载 作者:行者123 更新时间:2023-11-29 11:35:27 25 4
gpt4 key购买 nike

我想减去两个日期,这样只会相差 15 天,然后在没有用户交互的情况下自动发送电子邮件?这怎么可能?

这是我的 PHP 代码

<?php

$user = 'root';
$pass = '';
$con = 'pharmacy';
$con = new mysqli('127.0.0.1', $user, $pass, $con);

if(!$con)
{
echo 'Unable to Connect with Server';
}
if (!mysqli_select_db($con,'pharmacy'))
{
echo 'Database is Not Selected';
}
//select database
mysqli_select_db($con,'pharmacy');

//Expiry Date which is stored in Datebase
//Convert String into Date Format
$sql_unique=$con->query("SELECT exp_dt FROM scandrug");
$expiry = strtotime($sql_unique);
$newformat = date('d-m-Y',$expiry);

$day= date('d',$newformat); //Day of the month
$month= date('m',$newformat); //Month of the year
$year= date('Y',$newformat); //Year

//echo $newformat;

//Obtain current Date
$current_dt = new DateTime();
$current_dt= date('d-m-Y');

$dayy= date('d',$current_dt); //Day of the month
$monthh= date('m',$current_dt); //Month of the year
$yearr= date('Y',$current_dt); //Year

//echo $current_dt;
do{
if($day-$dayy==15 || $day-$dayy==-15 && $month-$monthh==01 || $month-$monthh==00 && $year-$yearr==0000)
{

}
else
{
//nothing will happen
}
}while(1);
?>

最佳答案

只需尝试这个即可找到两个日期之间的差异,然后按照您的需要进行操作

$datetime1 = new DateTime('2009-10-11');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%R%a days');

关于php - 如何在 PHP 中减去两个日期并在没有交互的情况下发送自动电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36667579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com