如何在php中获取更新日期小于30天的所有记录

编程入门 行业动态 更新时间:2024-10-10 08:19:56
本文介绍了如何在php中获取更新日期小于30天的所有记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从 mysql 数据库中获取从当前日期起 30 天内更新记录的所有记录,因为我使用了以下查询,但它无法正常工作.$tda 是当前日期,$prevmonth 是确切日期从当前日期回溯 30 天.请帮忙.谢谢.

I want to get all the records from mysql database who have updated their records within 30 days from the current date for that i have used the below query but it is not working properly. $tda is the current date and $prevmonth is the date of exactly 30 days back from the current date. Please help. Thanks.

$da=date('d'); $tda=date('d-m-Y'); $prevmonth = date(''.$da.'-m-Y', strtotime('-1 months')); $sql_q=executeQuery("select * from ".reg." where 'uid' !=".$_SESSION['uid']." AND Updatedate >= '$prevmonth' AND Updatedate <='$tda '");

推荐答案

你可以在mysql中做

You can do it in mysql as

`Updatedate` < DATE(NOW() - INTERVAL 30 DAY)

`Updatedate` < DATE_SUB(CURDATE(), INTERVAL 30 DAY)

对于 Varchar

For Varchar

STR_TO_DATE(Updatedate, '%Y-%m-%d') < DATE_SUB(CURDATE(), INTERVAL 30 DAY)

更新:

评论中发布的查询是错误的,应该是

The query posted in the comment is wrong and should be

$sql_q=executeQuery("select * from registration where `uid` != ".$_SESSION['uid']." AND STR_TO_DATE(Update_date, '%d-%m-%Y') < DATE_SUB(CURDATE(), INTERVAL 30 DAY)") ;

如果您要查找过去 30 天内的数据,则

If you are looking for data within last 30 days then

$sql_q=executeQuery("select * from registration where `uid` != ".$_SESSION['uid']." AND STR_TO_DATE(Update_date, '%d-%m-%Y') >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)") ;

更多推荐

如何在php中获取更新日期小于30天的所有记录

本文发布于:2023-10-17 09:33:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500474.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   如何在   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!