Last updated November 26, 2013. Created on November 26, 2013.
Edited by one_hoopy_frood. Log in to edit this page.

I found myself in need of a way to calculate the current application year for an application process. Because the site will take applications from year to year I wanted a way to have the system automatically figure out what the application year is. You can set the date after which applications move forward to the next application year. The application year is constant until the NEXT time the date passes and so on.

It does this in a simple logic process:

  1. get the current date and future date
  2. compare the current year's turnover date to the the turnover date
  3. if the date has passed already, add a year to the future date
  4. the "application year" becomes the four-digit year of the NEXT occurrence of the date in question.

I hope someone else finds a use for it; I was surprised how hard it was to logic through.

Example:

Assume that the deadline for all applications to be received and created is Aug 25 ("25 Aug"). If today's date is July 10 then the application year is the current year, say 2013. But if Aug 24 passes and today's date is Aug 28 the application year becomes 2014.

As is and unedited, the code below is the action from a rule whose trigger is on saving new content that populates a created content type's field value equal to the returned application year value.

<?php
// Set the date you like for the turnover event
$turnover_day_month = "25 Aug";

// Get the value of the date for this year
$future_date = strtotime($turnover_day_month." ".date("y"));
$current_date = time();

if (
$future_date < $current_date)
     {
$future_date = strtotime($turnover_day_month." ".date("y",strtotime("+1 year")));
}

// Just get the four digit year
$application_year = date('Y', $future_date);

return array(
0 => array('value' => $application_year));
?>

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.