note 124097 added to class.datetime

From: Date: Wed, 07 Aug 2019 09:13:42 +0000
Subject: note 124097 added to class.datetime
Groups: php.notes 
Request: Send a blank email to php-notes+get-211824@lists.php.net to get a copy of this message
When given 2 variables and you want to change the date of the first variable but not the time, it can be done like this: <?php // First date is today $dateOne = new DateTime(); // Second date is some date $dateTwo = new DateTime('14-10-1963'); echo 'Date one before change: ' . $dateOne->format('Y-m-d H:i:s'); echo '<br/>'; echo 'Date two: ' . $dateTwo->format('Y-m-d H:i:s'); // Now modify the date of variable $dateOne with the date of $dateTwo $dateOne->modify($dateTwo->format('Y-m-d')); echo '<br/>'; echo 'Date one after change: ' . $dateOne->format('Y-m-d H:i:s'); ?> Outputs: Date one before change: 2019-08-07 09:32:44 Date two: 1963-10-14 00:00:00 Date one after change: 1963-10-14 09:32:44 ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.195 (proxied: 217.121.48.75) ---- Manual Page -- http://php.net/manual/en/class.datetime.php Edit -- https://master.php.net/note/edit/124097 Del: integrated -- https://master.php.net/note/delete/124097/integrated Del: useless -- https://master.php.net/note/delete/124097/useless Del: bad code -- https://master.php.net/note/delete/124097/bad+code Del: spam -- https://master.php.net/note/delete/124097/spam Del: non-english -- https://master.php.net/note/delete/124097/non-english Del: in docs -- https://master.php.net/note/delete/124097/in+docs Del: other reasons-- https://master.php.net/note/delete/124097 Reject -- https://master.php.net/note/reject/124097 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#211824) next »