phpdatetimetodate
如果你的数据库中字段的类型设置为date类型,那么你在PHP端将时间转化为$time = date('Y-m-d');将这个时间存进去即可,还有一种方法就是你就数据库的字段的默认值设置为current_time,在PHP端存数据库就不需要考虑这个问题了
② php时间格式怎么转换
php日期格式转换总结:
<?php
//将当前时间转换成yyyy-mm-dd格式串,再转换成日期格式,绕了一圈哈
echo strtotime(date('Y-m-d',time()).' 00:00:00');
//将GNU 日期输入格式的字符转换成时间
echo strtotime('now');
//标准的字符串转换成时间
$t = '2012-9-10 15:18:06';
$time = strtotime($t);
//将时间转换成日期字符yyyymmdd,再转换成整型格式
$d = intval(date('Ymd',$time));
echo '付款时间:'.$d;
<?php
header("Content-type: text/html; charset=utf-8");
$txDate = '2016-06-16';
$dateTime1 = strtotime($txDate); //int 1466028000 将英文文本日期时间解析为 Unix 时间戳:
$dateTime2= date("Y-m-d H:i:s",$dateTime1); //string '2016-06-16 00:00:00'
(length=19) Date() 函数把时间戳格式化为更易读的日期和时间。
//拼接今日最后时间2016-06-16 23:59:59
$dateTime= date("Y-m-d H:i:s",strtotime(date("Y-m-d",strtotime($dateTime2))."+ 23 hours 59 minutes 59 seconds ")); //string '2016-06-16 23:59:59' (length=19)
$sql = select * form `vvt_user` where userid = 100 AND date_time >= $dateTime2 AND date_time <= $dateTime;?>