#44163 [Bgs]: Addition of more useful date time functions

From: Date: Tue, 19 Feb 2008 05:26:07 +0000
Subject: #44163 [Bgs]: Addition of more useful date time functions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-122444@lists.php.net to get a copy of this message
ID: 44163 User updated by: cool_lim_lp at yahoo dot com dot sg Reported By: cool_lim_lp at yahoo dot com dot sg Status: Bogus Bug Type: Feature/Change Request Operating System: any PHP Version: 5.2.5 New Comment: ok, tell me how do you calculate the no. of days difference between two given dates. Previous Comments: ------------------------------------------------------------------------ [2008-02-19 05:10:26] rasmus@php.net That's already there. Please see the date_modify() function in the manual. Also see date_parse(). ------------------------------------------------------------------------ [2008-02-19 05:05:55] cool_lim_lp at yahoo dot com dot sg Description: ------------ Is it possible to add more useful functions like date substraction and date addition and the ability to get individual date parts? For example, to get a date part, we have to do something like $datetime = new DateTime ('12 jan 2008'); $day = (int)$datetime->format('d'); We have to convert an internally stored int to a string and then back to an int again, duh. Why not simply introduce a 'getDay' function? $day = $datetime->getDay(); $year = $datetime->getYear(); Subtraction of two dates: First, we have to convert the datetime object to a UNIX timestamp, which has a very limited range and then perform some maths on this timestamp itself. It is very tedious and troublesome. for example to calculate the age of a person: $now = new DateTime ('now'); $dob = new DateTime ('19 jan 1955'); you have to first convert to a UNIX timestamp, but the dob is out of the range allowed. Or you could use date_parse to get some info and then perform some lengthy maths to calculate the age. Sometimes we also need to know the amount of time that has elapsed between two dates in terms of hours, minutes, seconds, years, or months etc. But currently, there is no easy way to calculate that using PHP 's built-in functions. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44163&edit=1

« previous php.bugs (#122444) next »