ID:               44163
 Updated by:       [EMAIL PROTECTED]
 Reported By:      cool_lim_lp at yahoo dot com dot sg
-Status:           Bogus
+Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: any
 PHP Version:      5.2.5
 New Comment:

Rasmus, most of the functions in the date() comments actually don't
work, so we can use something like this. I am hoping to manage to get it
into PHP 5.3.


Previous Comments:
------------------------------------------------------------------------

[2008-02-19 05:59:03] [EMAIL PROTECTED]

Right, date_diff would be useful, but date addition and the ability to
get individual date parts are there already in date_modify() and
date_parse().

------------------------------------------------------------------------

[2008-02-19 05:46:46] cool_lim_lp at yahoo dot com dot sg

look at the user notes at :

http://sg2.php.net/manual/en/function.date.php

see how many people have to write their own functions to do even simple
date calculations.

------------------------------------------------------------------------

[2008-02-19 05:26:06] cool_lim_lp at yahoo dot com dot sg

ok, tell me how do you calculate the no. of days difference between two
given dates.

------------------------------------------------------------------------

[2008-02-19 05:10:26] [EMAIL PROTECTED]

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

Reply via email to