lumen 5.7 - 如何使用 where 条件获取 UNIX 时间戳整数格式日期记录
lumen 5.7 - how to get UNIX timestamp an integer format date records with where condition
在非常古老的现有数据库上工作,有记录以 UNIX 时间戳和整数格式 存储,如下结构
id | name | email | datetime
---------------------------------------
1 | abc | abc@example.com | 1277812531
2 | xyz | xyz@example.com | 1277862176
3 | pqr | pqr@example.com | 1277926058
4 | wxy | wxy@example.com | 1278348102
5 | nnn | nnn@example.com | 1278381032
现在,我想流明查询日期时间是否等于通过参数传递以获取记录
该项目使用 lumen 5.7,主要问题之一是,数据库将时间戳存储为整数列中的 UNIX 时间戳,而不是时间戳列。我正在寻找处理此问题的最佳方法。
DB 原始查询并且工作正常
$response = Model::where(\DB::raw('DATE_FORMAT(FROM_UNIXTIME(datetime), "%Y-%m-%d")'), '=', $_search_date)->get();
这对我有用 :)
在非常古老的现有数据库上工作,有记录以 UNIX 时间戳和整数格式 存储,如下结构
id | name | email | datetime
---------------------------------------
1 | abc | abc@example.com | 1277812531
2 | xyz | xyz@example.com | 1277862176
3 | pqr | pqr@example.com | 1277926058
4 | wxy | wxy@example.com | 1278348102
5 | nnn | nnn@example.com | 1278381032
现在,我想流明查询日期时间是否等于通过参数传递以获取记录
该项目使用 lumen 5.7,主要问题之一是,数据库将时间戳存储为整数列中的 UNIX 时间戳,而不是时间戳列。我正在寻找处理此问题的最佳方法。
DB 原始查询并且工作正常
$response = Model::where(\DB::raw('DATE_FORMAT(FROM_UNIXTIME(datetime), "%Y-%m-%d")'), '=', $_search_date)->get();
这对我有用 :)