Compare dates between datetimes with Doctrine

后端 未结 3 471
萌比男神i
萌比男神i 2021-01-01 15:05

I have a Syfmony2 app with a table which has a date field. This date field is a DateTime type.

I need to get all the entities which the same date as now.

But

3条回答
  •  天命终不由人
    2021-01-01 15:47

    There is a difference between the date and datetime types in doctrine.

    date: Type that maps a SQL DATETIME to a PHP DateTime object.

    datetime: Type that maps a SQL DATETIME/TIMESTAMP to a PHP DateTime object.

    Make sure you have set the column type to date instead of datetime.

    Alternatively - as a workaround - you could get the day from the original date1 and then search between a same-day date2 -> 00:00:00 and same-day date3 -> 23:59:59 using a custom repository method.

提交回复
热议问题