Page 1 of 1
how to Figure out how many days it has been since a date
Posted: Thu Mar 29, 2012 9:55 am
by rileychilds
Hi I was wondering how do I Calculate how many weeks it has been since a date in unix time Here is what i have so far:
Code: Select all
<?php
include "database.php";
//mysql code to get unix time stamps
$dateout = 890179200;
//some while statment
echo "Overdue X days";
Echo "you owe $X in fines";
?>
Any Help?
Re: how to Figure out how many days it has been since a date
Posted: Thu Mar 29, 2012 10:00 am
by Celauran
If you're using PHP >= 5.3.0, check out
DateTime::diff
Re: how to Figure out how many days it has been since a date
Posted: Thu Mar 29, 2012 1:11 pm
by califdon
You might also find the PHP
strtotime() function useful for this.
Re: how to Figure out how many days it has been since a date
Posted: Thu Mar 29, 2012 3:39 pm
by rileychilds
I'm Still Somwhat confused i'm try to figure out how many days it has been since a date off of a unix timestamp (eg. 54823681) and then based on that calculate how many intervals of 14 there have been. I am trying to wirte code for a library software for my school

Re: how to Figure out how many days it has been since a date
Posted: Thu Mar 29, 2012 8:23 pm
by califdon
rileychilds wrote:I'm Still Somwhat confused i'm try to figure out how many days it has been since a date off of a unix timestamp (eg. 54823681) and then based on that calculate how many intervals of 14 there have been. I am trying to wirte code for a library software for my school

Probably the simplest and most direct way is to just subtract the unix timestamp for the beginning date from the unix timestamp for Now, which will give you the number of seconds difference, then take the integer or floor() (
http://www.w3schools.com/php/func_math_floor.asp) of the result of dividing that number of seconds by whatever interval you want. If it's 14 days, multiply 14 * 24 * 60 * 60 and use that as your divisor. OK?