Porl123 Posted March 6, 2011 Share Posted March 6, 2011 I have a php script that allows the user to enter a day, month and year, for example 10/10/2001. What I'm trying to do is find out how many years that date is from now, taking into account the days and months along with the years. So say I have the variables: <?php $day = 10; $month = 10; $year = 2001; ?> I've been thinking about this for a while now and I can't really think of how I would do it. If anyone can give me a hand I'd really appreciate it. (: Thanks! Quote Link to comment Share on other sites More sharing options...
ZacTopher Posted March 6, 2011 Share Posted March 6, 2011 first you find the difference between the two years and then you should have two if statements checking the following 1. is the given month higher than the current month 2. is the given month equal to the current month, if so, is the given day higher than the current day? if any of those are true you should substract 1 from the year difference NOTE: If you don't check if the year is zero then you will end up with -1 Quote Link to comment Share on other sites More sharing options...
Porl123 Posted March 6, 2011 Author Share Posted March 6, 2011 Thanks for the reply. Does this take leap years into account, btw? Quote Link to comment Share on other sites More sharing options...
Porl123 Posted March 6, 2011 Author Share Posted March 6, 2011 Or rather the different lengths of each month? Quote Link to comment Share on other sites More sharing options...
ZacTopher Posted March 6, 2011 Share Posted March 6, 2011 that checks only the day, month and year against the current date.. Quote Link to comment Share on other sites More sharing options...
Porl123 Posted March 6, 2011 Author Share Posted March 6, 2011 Ah, I've finally got my head around it. Thanks for the help Zac Quote Link to comment Share on other sites More sharing options...
ZacTopher Posted March 6, 2011 Share Posted March 6, 2011 You're welcome 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.