[英]PHP Is MySQL DATETIME Field 14 days ago from todays date
我正在嘗試編寫PHP代碼,以查看mysql數據庫中的日期(2013-06-05)是否為14天或更早。
我已經使用MySQL SELECT語句選擇了我需要的記錄:
$sql="SELECT * from table ";
$rs=mysql_query($sql,$conn) or die(mysql_error());
while($result=mysql_fetch_array($rs))
{
if(strtotime($result['datetime']) > strtotime('-14 days') )
{
echo 'yes';
}
}
但它沒有顯示我所回應的內容。 有任何想法嗎?
我基本上是在嘗試設置發票提醒系統。 我有3欄:
first_reminder
second_reminder
third_reminder
因此,在datetime
字段之后的14天,它將發送一封電子郵件並將電子郵件的發送日期放在first_reminder字段中,然后在first_reminder日期之后的7天,它將再次執行相同操作,依此類推...
您可以使用MySQL做到這一點,您必須對PHP有所不同。 查看是否有超過14天的時間。
select * from table where some_date < curdate() - interval 14 day
查看是否在最近的14天內。
select * from table where some_date > curdate() - interval 14 day
另一種方法是在DATEDIFF
函數中提取實際天數差作為計算(第一個數字減去第二個數字):
select *,DATEDIFF(CURDATE(),date_field) as days from table
然后在PHP中你可以做
if ($row['days'] > 14){
//it's two weeks old
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.