The time 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
chorage
Forum Newbie
Posts: 2
Joined: Tue Aug 05, 2008 7:22 am

The time between two dates

Post by chorage »

Hello there

I'm working on a sorta calendar project to be used with studies. It's a pretty simple PHP program, that lists some appointments and the status of those. The whole focus is to keep track of my deadlines. I was thinking it would be really cool, if i could make the program tell me how many days there is from the current date till deadline.

In short:

Is there a way to compare 2 dates (deadline and localtime) and output the time between them? Be it seconds, minutes whatever.

Thanks in advance

Chorage
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: The time between two dates

Post by jaoudestudios »

If you store the deadline date using php function time() and compare it with time() now then yes you can do anything!
chorage
Forum Newbie
Posts: 2
Joined: Tue Aug 05, 2008 7:22 am

Re: The time between two dates

Post by chorage »

Thanks a bunch, that worked for me :D

$timedifference = strtotime($deadline) - time();

or in days: $timedifference = (strtotime($deadline) - time())/3600/24;
Post Reply