|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-02-19 05:10 UTC] rasmus@php.net
[2008-02-19 05:26 UTC] cool_lim_lp at yahoo dot com dot sg
[2008-02-19 05:46 UTC] cool_lim_lp at yahoo dot com dot sg
[2008-02-19 05:59 UTC] rasmus@php.net
[2008-02-19 08:05 UTC] derick@php.net
[2008-02-19 08:48 UTC] rasmus@php.net
[2008-07-08 18:05 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 17:00:02 2025 UTC |
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.