gpt4 book ai didi

php - DateTimestamp 包含本月和年的 Laravel SQL 选择查询

转载 作者:可可西里 更新时间:2023-11-01 07:06:58 26 4
gpt4 key购买 nike

我正在尝试进行 SQL 查询,我可以在其中检查 DateTimestamp 是否包含本月和本年。

部分查询:

$leads = DB::table('leads') 
->leftJoin('invoices', function($join2) {
$join2->on('leads.id', '=', 'invoices.lead_id');
})
->where('invoices.chance', '!=', 0)
->where('invoices.updated_at', '=', date('m-Y')) //Check if DateTimestamp(updated_at) contains Year and month
->select('leads.*')

我用 date_parse, new DateTime() 试过了,但是没用。我做错了什么?

最佳答案

您可以使用 whereMonth()whereYear() 来实现这一点:

$leads = DB::table('leads') 
->leftJoin('invoices', function($join2) {
$join2->on('leads.id', '=', 'invoices.lead_id');
})
->where('invoices.chance', '!=', 0)
->whereMonth('invoices.updated_at', '=', date('m')) // changed
->whereYear('invoices.updated_at', '=', date('Y')) // changed
->select('leads.*');

关于php - DateTimestamp 包含本月和年的 Laravel SQL 选择查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34204617/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com