DDC-640: Changes to datetime property not persisting #792

Closed
opened 2026-01-22 12:50:36 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Jun 16, 2010).

Jira issue originally created by user garrett:

I've got an entity with a property declared as follows:

 /*** @Column(type="datetime") ***/
private $scheduledFor;

Changes made to this property via PHP's DateTime::setTime function do not persist

$obj->getScheduledFor()->setTime('08', '30', '00');
$em->persist($obj);
$em->flush();

In order to persist the changes I must do the following

$date = clone $obj->getScheduledFor();
$date->setTime('08', '30', '00);
$obj->setScheduledFor($date);
$em->persist($obj);
$em->flush();
Originally created by @doctrinebot on GitHub (Jun 16, 2010). Jira issue originally created by user garrett: I've got an entity with a property declared as follows: ``` /*** @Column(type="datetime") ***/ private $scheduledFor; ``` Changes made to this property via PHP's DateTime::setTime function do not persist ``` $obj->getScheduledFor()->setTime('08', '30', '00'); $em->persist($obj); $em->flush(); ``` In order to persist the changes I must do the following ``` $date = clone $obj->getScheduledFor(); $date->setTime('08', '30', '00); $obj->setScheduledFor($date); $em->persist($obj); $em->flush(); ```
admin added the Bug label 2026-01-22 12:50:36 +01:00
admin closed this issue 2026-01-22 12:50:38 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 16, 2010):

Comment created by romanb:

DateTime objects are treated as (immutable) value objects. To change a date, set a new date instead of "mutating" the existing date. The fact that DateTime is mutable is considered bad design. Dates dont change. When you change a date you get a new date.

@doctrinebot commented on GitHub (Jun 16, 2010): Comment created by romanb: DateTime objects are treated as (immutable) value objects. To change a date, set a new date instead of "mutating" the existing date. The fact that DateTime is mutable is considered bad design. Dates dont change. When you change a date you get a new date.
Author
Owner

@doctrinebot commented on GitHub (Jun 16, 2010):

Comment created by garrett:

Fair enough. Couldn't find any documentation on this hence the report. Sorry for the interruption.

@doctrinebot commented on GitHub (Jun 16, 2010): Comment created by garrett: Fair enough. Couldn't find any documentation on this hence the report. Sorry for the interruption.
Author
Owner

@doctrinebot commented on GitHub (Jun 16, 2010):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Jun 16, 2010): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#792