×

php获取当天的数据

php获取当天的数据(php获取当前时间提交数据库)

admin admin 发表于2023-03-25 11:07:09 浏览53 评论0

抢沙发发表评论

本文目录一览:

如何用PHP 获取今天之前,本周之前,本月之前,本年之前,今天,本周,本月,本年的数据呢

/*今天*/

select * from 表名 where to_days(时间字段) = to_days(now());

/*昨天*/

select * from 表名 where to_days(now())-to_days(时间字段) = 1;

/*近7天*/

select * from 表名 where date_sub(curdate(), interval 7 day) = date(时间字段);

/*查询距离当前现在6个月的数据*/

select * from 表名 where 时间字段 between date_sub(now(),interval 6 month) and now();

/*查询当前这周的数据*/

select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now());

/*查询上周的数据*/

select * from 表名 where yearweek(date_format(时间字段,'%Y-%m-%d')) = yearweek(now())-1;

/*查询当前月份的数据*/

select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(now(),'%Y-%m');

/*查询上个月的数据*/

select * from 表名 where date_format(时间字段,'%Y-%m')=date_format(date_sub(curdate(), interval 1 month),'%Y-%m');-php获取当天的数据

其它获取类似以上的代码显示

PHP+mysql 查询 今天,昨天,最近7天的数据?

今天

select * from 表名 where mytime(时间字段名) = mytime(now());

昨天

select * from 表名 where mytime( now( ) ) - mytime( 时间字段名) = 1

7天

select * from 表名 where date_sub(cur(), interval(7 day = date(时间字段名)

php中如何用关键字查询MySQL当天插入的内容,求代码

?php

$host="localhost";

$username="root";

$password="root";

$db="db4"; //库名

$mysql_table="person"; //表名

//连接数据库,面向过程

$conn=mysqli_connect($host,$username,$password);

if(!$conn){

echo "数据库连接失败";

exit;

}

//选择所要操作的数据库

mysqli_select_db($conn,$db);

//设置数据库编码格式

mysqli_query($conn,"SET NAMES UTF8");

//编写sql获取分页数据 SELECT * FROM 表名 LIMIT 起始位置,显示条数

//注意:以下id,name,age,say都是字段节点名,person是表名,db4是数据库名,think是指定的关键字.

$sql = 'SELECT id, name, age, say

FROM person

WHERE say LIKE "%think%" order by id ASC LIMIT '.($page-1)*$pageSize .",{$pageSize}";

// 节点名 关键字 节点名 可指定数量limit后可写一个指定的数字

//$sql="select * from $mysql_table"

//把sql语句传送到数据库

$result=mysqli_query($conn,$sql);

//将数据显示到table中,并未table设置格式

echo "div class='content'";

echo "table border=1 cellspacing=0 width=30% align=center";

echo "trtdID/tdtdNAME/tdtdsay/td/tr";

while ($row = mysqli_fetch_assoc($result)) {

echo "tr";

echo "td{$row['id']}/td";

echo "td{$row['name']}/td";

echo "td{$row['say']}/td";

echo "tr";

}

echo "/table";

echo "/div";

//释放结果

mysqli_free_result($result);

//关闭数据库

mysqli_close($conn);