the num of week between two dates

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
User avatar
lazerbri
Forum Newbie
Posts: 15
Joined: Sat Dec 27, 2003 8:17 am

the num of week between two dates

Post by lazerbri »

hi
Im trying to get the number of weeks between two timestamps
and display it in a readable format like
12 weeks and two days

this is not as easy as I thought it would be?

can any one help

thanks
Brian
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Just use a bit of maths. Once you have got the time between in seconds you can then do something like:

Code: Select all

$time = '50000'; //some random time

$weeks = floor((60*60*24*7)/$time);
$time -= $weeks*(60*60*24*7);

$days = floor((60*60*24)/$time);
$time -= $days*(60*60*24);

$hours = floor((60*60)/$time);
$time -= $hours*(60*60);

$mins = floor(60/$time);
$time -= $mins*60;

$secs = $time;
Then output it as you wish.
User avatar
lazerbri
Forum Newbie
Posts: 15
Joined: Sat Dec 27, 2003 8:17 am

thanks this is good stuff

Post by lazerbri »

thanks this is good stuff and it does the job

thanks
brian
Post Reply