i am trying to write PHP Code that will see if a date in a mysql database (2013-06-05) was 14 days ago or more.
i have selected the records i need using the MySQL SELECT Statement:
$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';
}
}
but its not displaying what i have echoed. any ideas?
im basically trying to setup an invoice reminder system. i have 3 columns:
first_reminder
second_reminder
third_reminder
so, 14 days after the datetime
field it will send an email and put the date the email was sent in the first_reminder field, then 7 days after the first_reminder date it will do the same again and so on...
You can do this with MySQL, you'll have to think about the PHP a little differently. To see if something is beyond 14 days in the past.
select * from table where some_date < curdate() - interval 14 day
To see if it's within the last 14 days.
select * from table where some_date > curdate() - interval 14 day
Another way to do it would be to pull the actual number of days difference as a calculation (first number subtracts the second number) in the DATEDIFF
function:
select *,DATEDIFF(CURDATE(),date_field) as days from table
Then in PHP you could do
if ($row['days'] > 14){
//it's two weeks old
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.