note 48325 added to function.time

From: Date: Sun, 19 Dec 2004 15:49:14 +0000
Subject: note 48325 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-82045@lists.php.net to get a copy of this message
I think this note could help to people they want to avoid mysql use, and just to generate the websites dynamically each 5 minutes or something similar, so you just need to know the difference of the index with the current date time. The best solution is implemented using this simple but usefull functions. $month1 = date('n',$timestamp1); $month2 = date('n',$timestamp2); $diff = $month2-$month1; echo(($diff > 0 ? $diff-1 : $diff+1)); ---- First date: 920264400 Second date: 974240831 $differecne = $first - $second; echo $difference; Returns: Difference: 53976431 $diffday = $difference/86400; echo "$diffday (days)"; Returns this: Difference: 624.73377314815 (days) How can I further format this figure to display like: Difference: 624 days, X hours, X minutes, and X seconds $string_difference = date("H:m:s",mktime(0,0,$diff,0,0,0)) // I think that'll work. ---- $filemod = filemtime( 'headlines.txt' ); $now = time(); $seconds = $now - $filemod; /**************************** Make Minutes ****************************/ $minutes = floor( $seconds / ( int )60 ); /**************************** Get Left Over Seconds ****************************/ $left = $minutes * ( int )60; $a_seconds = $seconds - $left; /**************************** Output Message ****************************/ echo( 'File last modifed ' . $minutes . ' minute(s) and ' . $a_seconds . ' second(s) ago.' ); I hope it helps people. Raul Mate Galan Ceo Buenhospedaje www.buenhospedaje.com ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48325 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48325&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48325&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48325&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48325&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48325&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48325&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48325&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82045) next »