rvdb86 Posted October 15, 2009 Share Posted October 15, 2009 Hi, I have the following code to count the number of days between two dates: strtotime($endDate) - strtotime($fixedStartDate)) / (60 * 60 * 24) The problem is that when I tested it with the start date: 2009-01-01 and end date: 2009-02-10 the result was 40 when really there are 41 days?? Anyone know what i am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/177838-solved-finding-number-of-days-between-dates-problem/ Share on other sites More sharing options...
cags Posted October 15, 2009 Share Posted October 15, 2009 Look at the logic behind what your saying. Take it as day of the year. 01/01 is the first of the year so we'll take it as 1. 02/10 is the tenth day of the second month. The first month (January) has 31 days, making the 10th of February the 41st day of the year (the 10 in February plus the 31 from January). So we now have 41 - 1 which unless I'm mistaken is 40. Basically the maths you are doing says on the 41st day of the year 40 days have passed. For calculating inclusive time periods you'll have to add one to the result because you are including both the first and last day. Quote Link to comment https://forums.phpfreaks.com/topic/177838-solved-finding-number-of-days-between-dates-problem/#findComment-937706 Share on other sites More sharing options...
rvdb86 Posted October 16, 2009 Author Share Posted October 16, 2009 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/177838-solved-finding-number-of-days-between-dates-problem/#findComment-937997 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.