mysql 日期相等,MySQL查询选择所有与日期时间相等的日期等于今天

I have a database table something like this:

Col_1 | Datetime

test1 2015-12-19 09:00:00

test2 2015-12-18 12:30:00

test3 2015-12-19 10:00:00

test4 2015-12-19 16:45:00

I am trying to select in my query all results where the datetime is equal to today's date, although when I simply use something like:

$today = date("Y-m-d");

SELECT * FROM table WHERE datetime = '$today'

It just doesn't seem to work? And if I add the time in to $today it would only select those results which are equal to the exact current time which is not what I want?

Any idea as to how I can do this? I've even gone so far as to this which is totally stupid (Although it was about 3am in the morning when I coded it):

$now = date("Y-m-d H:m:s", strtotime('midnight'));

$todays = date(strtotime('midnight'));

$take24hours = date("Y-m-d H:m:s", strtotime('-24 hours', $todays));

$results = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM table WHERE date_added > '$take24hours' AND date_added < '$now')"));

解决方案

Can do this entirely in sql transaction ( no need for php date formatting ) :

SELECT * FROM table WHERE date(`datetime`) = current_date;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值