RE: Question about date calculations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When I try this method:

 

$interval = $dteStartDate[$intCnt]->diff($dteEndDate[$intCnt]); I get the following error when I run the page: 

" Fatal error : Call to undefined method DateTime::diff() in /var/www/evalHomeLime.php on line 254"   
 

 

Thank you

 


Eric H. Lommatsch
Programmer
Pivotal Data Incorporated  
2087 South Grant Street
Denver, CO 80210
Tel 303-777-8939 Ext 23
Fax 888-282-9927

 


www.pivotaldata.com 

 


ericl@xxxxxxxxxxxxxxx 

 

 
 
-----Original message-----
From: admin@xxxxxxxxxxxxxxxxxxx
Sent: Thu 29-12-2011 16:07
To: 'Fatih P.' <fatihpiristine@xxxxxxxxx>; 'Frank Arensmeier' <farensmeier@xxxxxxxxx>; 
CC: 'Eric Lommatsch' <ericl@xxxxxxxxxxxxxxx>; php-general@xxxxxxxxxxxxx; 
Subject: RE:  Question about date calculations


> -----Original Message-----
> From: Fatih P. [mailto:fatihpiristine@xxxxxxxxx]
> Sent: Thursday, December 29, 2011 5:10 PM
> To: Frank Arensmeier
> Cc: Eric Lommatsch; php-general@xxxxxxxxxxxxx
> Subject: Re:  Question about date calculations
> 
> On Thu, Dec 29, 2011 at 11:40 PM, Frank Arensmeier
> <farensmeier@xxxxxxxxx>wrote:
> 
> > 29 dec 2011 kl. 22.22 skrev Eric Lommatsch:
> >
> > > So far in looking at the functions that are available at
> > > http://www.php.net/manual/en/ref.datetime.php I have not been able
> to
> > figure
> > > out how to do what I need to do.  Below is a snippet showing
> > approximately
> > > what I am trying to do.
> >
> > On the same page you are referring, there are plenty of examples on
> how to
> > calculate the difference between two dates. Choose one and see if it
> fits
> > your bill. Or is there any particular reason why you're writing your
> "own"
> > function?
> >
> > http://www.php.net/manual/en/ref.datetime.php#78981
> >
> > /frank
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> since you have everything in database tables why not to do this
> calculation
> on database side which would be much appropriate place ?
> 
> /* columns
> date_start = '2011-02-08';
> date_end = ' 2011-03-04';
> */
> 
> select DATEDIFF(date_end, date_start);
> 
> http://dev.mysql.com/doc/refman/5.5/en/date-and-time-
> functions.html#function_datediff


I looked at this answer and see the date is from an array of a database and not 2 fields with in the table.
While the DATEDIFF() is very useful in queries this will not help you unless both fields are in the table.

Try this example

$dteStartDate[$intCnt] = new DateTime($row[10]);
$dteEndDate[$intCnt] =new DateTime($row[11]);
$interval = $dteStartDate[$intCnt]->diff($dteEndDate[$intCnt]);
echo $interval->format('%R%a days');









[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux