I am working on a file management project, where I have expiry dates for every file. I need to list all the files that are going to expire the next year. What will be the SQL query?
should it be something like:
$date = date ('Y-m-j');
$newdate = strtotime ( '+1 year' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );
$sql = "SELECT * FROM `files` WHERE `expDate` = year ($newdate)" ;
如果expDate
在mysql时间戳( yyyy-mm-dd hh:mm:ss
)中,则可以使用
DATE_ADD(`expDate`, INTERVAL 1 YEAR)
您可以使用mysql DATE_ADD添加年份
$sql = "SELECT * FROM `files` WHERE `expDate` = YEAR(DATE_ADD($date, INTERVAL 1 YEAR))";
尝试:
$sql = "SELECT * FROM `files` WHERE YEAR(`expDate`) = YEAR(NOW()) + 1" ;
Try this
$newdate = date ( 'Y-m-j' , strtotime('+1 year') );
$sql = "SELECT * FROM `files` WHERE `expDate` = year ($newdate)" ;
or
$sql = "SELECT * FROM `files` WHERE `expDate` = YEAR(NOW())+1;
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.