HuggieBear Posted September 4, 2006 Share Posted September 4, 2006 What's the easiest way to work out the number of months between two dates?I've been looking at the date() and time() functions and can probably figure out a way to work it but wondered if their was a function already?RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/19678-solved-months-between/ Share on other sites More sharing options...
AndyB Posted September 4, 2006 Share Posted September 4, 2006 Define 'number of months'. How many months between September 1 and October 31? How many months between September 30 and October 1? Quote Link to comment https://forums.phpfreaks.com/topic/19678-solved-months-between/#findComment-85790 Share on other sites More sharing options...
HuggieBear Posted September 4, 2006 Author Share Posted September 4, 2006 Sorry,How many months between January 2005 and September 2006.The months will be between whole months, not particular dates.Rich Quote Link to comment https://forums.phpfreaks.com/topic/19678-solved-months-between/#findComment-85793 Share on other sites More sharing options...
GingerRobot Posted September 4, 2006 Share Posted September 4, 2006 This would work:[code]<?php$curr_year = date('Y');$curr_month =date('m');$old_year = 2004;$old_month = 8;$months_passed = ($curr_year-$old_year)*12+$curr_month-$old_month;echo $months_passed;?>[/code]Purely based on calendar months. Quote Link to comment https://forums.phpfreaks.com/topic/19678-solved-months-between/#findComment-85798 Share on other sites More sharing options...
HuggieBear Posted September 4, 2006 Author Share Posted September 4, 2006 Perfect, thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/19678-solved-months-between/#findComment-85840 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.