繁体   English   中英

当前月份的日期格式问题

[英]Date format issue for current month

我的数据库中的日期格式是dd/mm/yyyy 。我的日期是02/01/2019, 02/03/2019, 07/05/2019 我将它们存储在varchar (我不能使用日期格式,因为我的整个项目会搞砸。)

在这里,我只需要当月 EG 的日期:

$currentMonth = date('m'); 
$receipt = DB::table('receipt_payment')
    ->whereRaw('MONTH(due_date) = ?', [$xcurrentMonth])
    ->get();

但我得到count()==0

您好您可以尝试在 mysql 中将字符串转换为日期。

您可以使用str_to_date()

供参考https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_str-to-date

$currentMonth = date('m'); 
$receipt = DB::table('receipt_payment')
    ->whereRaw('MONTH(str_to_date(due_date , '%m/%d/%Y')) = ?', [$xcurrentMonth])
    ->get();

希望这可以帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM