Sim Posted February 11, 2012 Share Posted February 11, 2012 What php function exists to calculate the number of days between two timestamp's. Quote Link to comment Share on other sites More sharing options...
Uridium Posted February 11, 2012 Share Posted February 11, 2012 Sim i found this not sure if its what your after but it does calculate 2 date differences using php http://stackoverflow.com/questions/2040560/how-to-find-number-of-days-between-two-dates-using-php Quote Link to comment Share on other sites More sharing options...
Uridium Posted February 11, 2012 Share Posted February 11, 2012 also found these 2 pages http://www.akadia.com/services/ora_date_time.html and http://www.if-not-true-then-false.com/2010/php-calculate-real-differences-between-two-dates-or-timestamps/ Quote Link to comment Share on other sites More sharing options...
Sim Posted February 11, 2012 Author Share Posted February 11, 2012 I am trying to get the # of days, hours, minutes between two dates. checking out your links now. Thanks illusions Quote Link to comment Share on other sites More sharing options...
Spudinski Posted February 11, 2012 Share Posted February 11, 2012 Link #3. -tooshort- Quote Link to comment Share on other sites More sharing options...
Sim Posted February 11, 2012 Author Share Posted February 11, 2012 I seen the DateDiff:: on php.net. Everytime I try to use that on my server, it says something about the function not existing... Quote Link to comment Share on other sites More sharing options...
Sim Posted February 11, 2012 Author Share Posted February 11, 2012 Heres what I got so far: I am not sure if its correct or not either... According to that site, my days should be correct: My hours can change by changing dates but my minutes never change... //vars $current_date_stamp = time(); $cruise_date_stamp = mktime($_REQUEST['hour'], $_REQUEST['min'], 0, $_REQUEST['month'], $_REQUEST['day'], $_REQUEST['YYYY']); $cruise_date = date("F j, Y", $cruise_date_stamp); $date_diff = $cruise_date_stamp - $current_date_stamp; $days = floor($date_diff/(60*60*24)); $hours = floor($date_diff/(60*60*24*60)); $mins = floor($date_diff/(60*60*24*60*60)); echo "Cruise Date Stamps: " . $cruise_date_stamp; echo "<BR>Current Date Stamp: " . $current_date_stamp; echo "<BR>Stamp Difference: " . $date_diff; echo "<br>Cruise Date: " . $cruise_date; echo "<br># of days: " . $days; echo "<br># of hours: " . $hours; echo "<br># of minutes: " . $mins . "<BR>"; Quote Link to comment Share on other sites More sharing options...
Uridium Posted February 11, 2012 Share Posted February 11, 2012 (edited) http://www.w3schools.com/sql/func_datediff.asp http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_datediff Edited February 11, 2012 by illusions Quote Link to comment Share on other sites More sharing options...
Sim Posted February 11, 2012 Author Share Posted February 11, 2012 damn I feel dumb, problem is I am not using a database ;-=] Quote Link to comment Share on other sites More sharing options...
Uridium Posted February 11, 2012 Share Posted February 11, 2012 Cant help you any further Sim ive never used datediff before :( Quote Link to comment Share on other sites More sharing options...
Spudinski Posted February 11, 2012 Share Posted February 11, 2012 damn I feel dumb, problem is I am not using a database ;-=] Why on earth would you need a DBMS for calculations, when you have PHP? Quote Link to comment Share on other sites More sharing options...
Uridium Posted February 11, 2012 Share Posted February 11, 2012 found this but i still think it uses a table http://www.sqlteam.com/article/datediff-function-demystified Quote Link to comment Share on other sites More sharing options...
bluegman991 Posted February 11, 2012 Share Posted February 11, 2012 (edited) Assuming you mean you want to find the exact time between 2 dates. This is what i made up. [noparse]function timeDiff($ts1,$ts2) { $ts1=(int) $ts1; $ts2=(int) $ts2; $time=max($ts1,$ts2)-min($ts1,$ts2); $years=floor($time/60/60/24/364.25); $time=(float) ($time-($years*364.25*24*60*60)); $days=floor($time/60/60/24); $time=(float) ($time-($days*24*60*60)); $hours=floor($time/60/60); $time=(float) ($time-($hours*60*60)); $minutes=floor($time/60); $time=(float) ($time-($minutes*60)); $seconds=(float) $time; $return=$years>0 ? $years.'y' : ''; $return.=$days>0 ? (empty($return) ? '' : ' ').$days.'d' : ''; $return.=$hours>0 ? (empty($return) ? '' : ' ').$hours.'h' : ''; $return.=$minutes>0 ? (empty($return) ? '' : ' ').$minutes.'m' : ''; $return.=$seconds>0 ? (empty($return) ? '' : ' ').$seconds.'s' : ''; $return=empty($return) ? 'NOW!' : $return; return $return; }[/noparse] Edited February 11, 2012 by bluegman991 Quote Link to comment Share on other sites More sharing options...
Sim Posted February 11, 2012 Author Share Posted February 11, 2012 Awesome, for some reason I am thinking you guys are the best right now. LoL's. ") Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.