View Full Version : Difference between 2 dates

10-27-2003, 03:10 PM
You know in ASP you can use the DateDiff function to determine difference in days between 2 given dates.... how can this be done in PHP with the date format as: dd mmm yyyy? any examples?


10-27-2003, 05:00 PM
Unsure, but using a timestamp, for each xxxxxx seconds = 1 day..

Duration of time Time in Seconds
One Second 1
One Minute 60
One Hour 3600
One Day 86400
One Week 604800
One Year 31449600
One Leap Year 31536000
One Decade 314496000
One Average Life-Time 2515968000
One Century 3144960000
One Millennium 31449600000

11-27-2003, 11:22 AM

I'm pulling dates from an oracle database in the format DD/MM/YYYY - e.g. - 21/07/2003

I would like to convert it to - DD MMM YYYY - e.g. 21 Jul 2003

When I try:-

print date("d M Y", strtotime("$due_date"));

it returns:

07 Sep 2004

So I guess its thinking my month is the day and the day is the month and therefore changing the year....

Any ideas to correct this?

11-27-2003, 03:46 PM
any ideas on this?

11-27-2003, 04:15 PM
I've been also trying to change its format in the PL/SQL code in my stored procedure using TO_CHAR (trying a different angle)

but I can't seem to do that either...

I'm stuck in a rut!!

any one else had this prob with oracle date formats?

11-27-2003, 07:05 PM
messy but works ..

function date_diff( $d1 , $d2 ){
$bits = explode( ' ' , $d1 ) ;$d1=mktime (0,0,0,$bits[1],$bits[0],$bits[2]);
$bits = explode( ' ' , $d2 ) ;$d2=mktime (0,0,0,$bits[1],$bits[0],$bits[2]);
$diff = ($d1>$d2) ? $d1-$d2 : $d2-$d1;
return ($diff / 24 ) / 3600;
echo date_diff( '10 02 2000','10 03 2000' ) ;

your DB should be able to return a timestamp , mysql can calculate the difference between dates , I am sure Oracle can of course but I would not know how, these things are best done via the DB

11-27-2003, 07:09 PM
, strtotime() requires some textual content ... eg it can work out what 'next thursday' means as well as '10 June 2003' , but just given numbers it has no way of telling which is the month & which is the day etc .. see my post in your other thread .. am merging the 2 threads BTW as its basically the same subject.