Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2001032

Re: [PHP] Date difference From: bill (bill <email protected>)
Date: 03/31/01

Lots of ways to do it, here's one.

Convert them both to unix timestamps and subtract.

$nowstamp=mktime() ;

$result=mysql_query(SELECT UNIX_TIMESTAMP(mydatefield) AS dbdate FROM
mydatabase);

$row=mysql_fetch_array($result);

$dbdate=$row["dbdate"];

$thedifference=$nowstamp - $dbdate;

//above gives you the difference in seconds.

$daydifference = intval($thedifference / 86400);

// 86400 is number of seconds in a day
// intval because I don't want partial days, just number of days
// $daydifference above gives you the difference in days

kind regards,

bill

ravi <email protected> wrote:

> Dear Friends,
>
> I am accessing a MySQL database through PHP.
>
> I have to calculate the difference between todays date and the date obtained
> from MySQL database.
>
> The Database string is in the form of \"yyyy-mm-dd\".
>
> I have to convert the above string into unix timestamp so that i can calcualte
> the difference between the two time stamps.
>
> Please help me in this regard.
>
> Thanking you,
>
> B. Raveendra Reddy
> National Law School of India University
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe <email protected>
> For additional commands, e-mail: php-general-help <email protected>
> To contact the list administrators, e-mail: php-list-admin <email protected>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>