Jump to content


Photo

How do I get the last occurrence of a date?


  • Please log in to reply
6 replies to this topic

#1 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 14 August 2006 - 06:13 PM

Let me try this again. Our fiscal year begins on July 1, so how do I get the last occurrence of July 1? Example: 07012006. I also want it to know and post the correct year.

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 14 August 2006 - 06:16 PM

Kinda vague.

Where do you want to get this last occurance? From a database? What type of database? MySQL? Can you post the current code you have? What format are these dates stored as?
PHP Ninja

#3 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 14 August 2006 - 06:31 PM

Kinda vague.

Where do you want to get this last occurance? From a database? What type of database? MySQL? Can you post the current code you have? What format are these dates stored as?


Sorry I wasn't more clear. No, I don't mean the last occurrence with data. I mean the last time that date happened. For example, the last time it happened was July 1, 2006. If I had ran this program back in May or whatnot, then it would show the last occurrence as July 1, 2005, and so on.


#4 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 14 August 2006 - 06:45 PM

You will need to store that information in order to make a reference to the last time the script was last accessed. If that is indeed your goal. Still unclear as to what it is you're asking. Regardless of what you're asking though, you will need to store data to make a reference to it, or compare it.
PHP Ninja

#5 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 14 August 2006 - 06:55 PM

You will need to store that information in order to make a reference to the last time the script was last accessed. If that is indeed your goal. Still unclear as to what it is you're asking. Regardless of what you're asking though, you will need to store data to make a reference to it, or compare it.


Okay, I guess I'm not expressing myself very well. Sorry, but this is also a bit confusing to me. It's actually very simple. What year was the last occurrence of July 1? That's it. As of right now, the answer would be July 1, 2006. This time next year, the code will show that the last occurrence was July 1, 2007, and so on. Our fiscal year begins July 1, but I need it to be Year-aware.

Make sense?



#6 GingerRobot

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

Posted 14 August 2006 - 07:40 PM

Err...
<?php
$curr_month = date('n');
$curr_day  = date('j');
$curr_year = date('Y');
if(($curr_month ==6 && $curr_day >= 1) || $curr_month >6){
$last = $curr_year;
}else{
$last = $curr_year - 1;
}
echo 'July 1 '.$last;
?>

Untested, but should work

#7 Moron

Moron
  • Members
  • PipPipPip
  • Advanced Member
  • 368 posts

Posted 14 August 2006 - 08:14 PM

Thanks, Ginger! That works!

:)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users