how to Figure out how many days it has been since a date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rileychilds
Forum Newbie
Posts: 14
Joined: Mon Feb 06, 2012 5:43 pm

how to Figure out how many days it has been since a date

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how to Figure out how many days it has been since a date

Post by Celauran »

If you're using PHP >= 5.3.0, check out DateTime::diff
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: how to Figure out how many days it has been since a date

Post by califdon »

You might also find the PHP strtotime() function useful for this.
rileychilds
Forum Newbie
Posts: 14
Joined: Mon Feb 06, 2012 5:43 pm

Re: how to Figure out how many days it has been since a date

Post 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 :banghead:
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: how to Figure out how many days it has been since a date

Post 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 :banghead:
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?
Post Reply