Jump to content


Photo

*SOLVED* Months between


  • Please log in to reply
4 replies to this topic

#1 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 04 September 2006 - 03:41 PM

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?

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 04 September 2006 - 03:45 PM

Define 'number of months'. How many months between September 1 and October 31? How many months between September 30 and October 1?
Legend has it that reading the manual never killed anyone.
My site

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 04 September 2006 - 03:47 PM

Sorry,

How many months between January 2005 and September 2006.

The months will be between whole months, not particular dates.

Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 04 September 2006 - 03:50 PM

This would work:
<?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;
?>

Purely based on calendar months.

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 04 September 2006 - 04:33 PM

Perfect, thanks  :)
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users