需求, 查询时间是否在某一天中, 例如明天
遇到的问题:
strtotime() 字符串转时间戳 date() 时间戳转为字符串
1. strtotime(date('Y-m-d')) 返回今天的时间戳, PS: 这里要注意: 是今天凌晨0点的时间戳
strtotime('2019-11-14 15:00:00') 返回这个时刻的时间戳
2. strtotime(date('Y-m-d H:i:s')) 注意, 这种情况返回的就是现在此刻的时间戳.
3. strtotime(date('Y-m-d H:i:s')) 和 strtotime(date('Y-m-d h:i:s')) 这里要注意, H大写表示24小时制, h小写表示12小时制 T.T
4. 时间戳转为日期字符串 date('Y-m-d H:i:s', 1569381203)
5. tp5查询如下,这里注意, 明天凌晨 date('Y-m-d', strtotime('+1 day')), 后天凌晨 date('Y-m-d', strtotime('+2 day')), 这里不能加上 H:i:s 如果加上了, 那就格式化到此刻了.就不是凌晨0点了.
Db::name('cai')->whereTime('yuyue_time', 'between', [date('Y-m-d', strtotime('+1 day')),date('Y-m-d', strtotime('+2 day'))])->find()
如上,用到了 between 方法
// 时间区间查询
Db::table('think_user')->whereTime('birthday', 'between', ['1970-10-1', '2000-10-1'])->select();
这里的区间, 都是表示 当日的凌晨0点.这一点要注意.
所以例如今天是 2019年09月25日11:22:21, 我要获取明天一天的区间. 就要用
date('Y-m-d', strtotime('+1 day')) ,不能加H:i:s 返回的是 2019-09-26 没有分秒表示0点0分0秒
date('Y-m-d', strtotime('+2 day')) ,不能加H:i:s 返回的是 2019-09-27 没有分秒表示0点0分0秒
所以上面2个区间加一起, 就是 9月26日一天的整个区间!