note 124954 added to class.dateinterval

From: Date: Mon, 27 Apr 2020 19:37:01 +0000
Subject: note 124954 added to class.dateinterval
Groups: php.notes 
Request: Send a blank email to php-notes+get-214546@lists.php.net to get a copy of this message
Many people have commented on doing a reverse interval on a date time. I personally find a backwards year to be a little strange to think about and instead opt to work with just intervals. This is the easiest I have found. <?php $one_year = new DateInterval('P1Y'); $one_year_ago = new DateTime(); $one_year_ago->sub($one_year); ?> Instead of: <?php $one_year_ago = new DateInterval( "P1Y" ); $one_year_ago->invert = 1; $one_year_ago = new DateTime(); $one_year_ago->add($one_year); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 38.142.137.34 (proxied: 67.177.16.113) ---- Manual Page -- http://php.net/manual/en/class.dateinterval.php Edit -- https://master.php.net/note/edit/124954 Del: integrated -- https://master.php.net/note/delete/124954/integrated Del: useless -- https://master.php.net/note/delete/124954/useless Del: bad code -- https://master.php.net/note/delete/124954/bad+code Del: spam -- https://master.php.net/note/delete/124954/spam Del: non-english -- https://master.php.net/note/delete/124954/non-english Del: in docs -- https://master.php.net/note/delete/124954/in+docs Del: other reasons-- https://master.php.net/note/delete/124954 Reject -- https://master.php.net/note/reject/124954 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214546) next »