簡體   English   中英

Laravel:嘗試僅比較簡單的日期,而不是小時,分鍾和秒

[英]Laravel: Trying to compare only the simple date, not hours minutes and seconds

$datetime = new DateTime('today');
$datetime->modify('+2 day');

$expired_tags = DB::table('tags')
        ->where('active', '=', 1)
        ->where('expiry_date', '=', $datetime)
        ->get();

我想了解如何提出以下要求:

給我距離過期兩天的所有標簽。 但是以上內容似乎考慮了小時,分鍾和秒數……我只需要詢問年,月,日並比較兩個日期的方面。

好吧,所以我想出了一種很棒的方式來做我想要的...

$starting_time = new DateTime('today');
$starting_time->modify('+1 day');

$ending_time = new DateTime('today');
$ending_time->modify('+1 day +23 hours +59 minutes +59 seconds');

$expired_tags = DB::table('tags')
        ->where('active', '=', 1)
        ->whereBetween('expiry_date', array($starting_time, $ending_time))
        ->get();

這將在下一個日歷日中的任何時間獲取具有datetime時間的所有記錄! :)

$today = new DateTime('today');

$expired_tags = DB::table('tags')
        ->where('active', '=', 1)
        ->where('expiry_date', '>=', $today->modify('+1 day')->format('Y-m-d'))
        ->where('expiry_date', '<',  $today->modify('+1 day')->format('Y-m-d'))
        ->get();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM