#1
  1. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Any recommendations?

    I have a client who wants a "renewal" notification type schema..

    ordinarily this is no problem, as most places
    do membership renewals on an anniversay date.

    but not these guys..

    here's an overview:

    If a person joins before Sep 1 of a given year, they renew on the "1st of Jan"..

    If the person joins after Sep 1 of the given year, then their renewal falls "13 months" later.. on Jan 1.

    If that's confusing, let's use this year as an example.

    If I joined the organization today, (prior to sep 1) I would have to renew my membership on Jan 1, 2001.

    But, If I waited till sep 2 of 2000 (this year) to join, I would not have to renew my membership until Jan 1, 2002.

    ---------------------------------------------
    So, here's the question?
    ---------------------------------------------

    1) Has anyone ever had to work with something like this?

    2) Would you recommend using PHP's "RayDay" function to obtain the "day of the year"?

    3) Or would it be better to work this based on the Unix "time()" functions?

    I'm obviously at a loss of which way to approach this thing.

    Granted, I could probably work it
    from the time() operations, determine the
    day/month and then increment from that.

    But that doesn't account for those darned
    "leap years"..

    any thoughts?


    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    43
    Rep Power
    15
    Renewal is always on jan 1 in any case.
    All you need is the correct year.

    Do something like this:
    // Get todays date
    <?php
    $month = date("m");
    $day = date("d");
    $year = date("Y");
    $time_now = mktime(0,0,0,$month,$day,$year);
    $time_threshold = mktime(0,0,0,9,1,$year);
    if( $time_now <= $time_threshold ) {
    $renewal_year = $year+1;
    }
    else {
    $renewal_year = $year+2;
    }
    $renewal_date = date("m-d-Y",mktime(0,0,0,1,1,$renewal_year)); // jan. 1 renewal year YYYY
    echo $renewal_date;
    php?>

    Of coarse I don't know where the dates are coming from or going to. Maybe a form or database. If you want to be database compatible the use Y-m-d instead of m-d-Y when you get the renewal date. mktime accounts for leap years. It's also handy for adding days months years with overlap doesn't matter it's always right. such as
    Say the date is 1-1-2000:
    $newdate = mktime(0,0,0,$month+13,$day,$year);
    will add 13 months then just use:
    $some_date = date("m-d-Y",$newdate);
    Now $some_date will equal 2-1-2001.
    Good luck hope it helps.

    ------------------
    lhallusa
    webpatron.com

    [This message has been edited by lhallusa (edited July 24, 2000).]
  4. #3
  5. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by lhallusa:
    Renewal is always on jan 1 in any case.
    All you need is the correct year.

    Do something like this:
    // Get todays date
    <?php
    $month = date("m");
    $day = date("d");
    $year = date("Y");
    $time_now = mktime(0,0,0,$month,$day,$year);
    $time_threshold = mktime(0,0,0,9,1,$year);
    if( $time_now <= $time_threshold ) {
    $renewal_year = $year+1;
    }
    else {
    $renewal_year = $year+2;
    }
    $renewal_date = date("m-d-Y",mktime(0,0,0,1,1,$renewal_year)); // jan. 1 renewal year YYYY
    echo $renewal_date;
    php?>

    Of coarse I don't know where the dates are coming from or going to. Maybe a form or database. If you want to be database compatible the use Y-m-d instead of m-d-Y when you get the renewal date. mktime accounts for leap years. It's also handy for adding days months years with overlap doesn't matter it's always right. such as
    Say the date is 1-1-2000:
    $newdate = mktime(0,0,0,$month+13,$day,$year);
    will add 13 months then just use:
    $some_date = date("m-d-Y",$newdate);
    Now $some_date will equal 2-1-2001.
    Good luck hope it helps.
    [/quote]

    I think I'd still need to work with an
    if/else if (month >= 9) ... it would also have to work, I think, if (month == 9) +13 to month(s), if (month == 10) +12 and so on...

    At the present, they are being stored in a mysql database.. but I've been storing the
    dates in "Unix" time format..

    so I would simply be pulling the column value out and passing it through
    the "date("m d y H.i.s", $value);

    to translate it over into human form...

    I'm assuming that in order to this, I'd have to use one of the jDToJulian functions? or perhaps the jDTounix function..

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  6. #4
  7. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    How about this, un-tested, but a thought on the whole process:

    $m = date("m",time());//get current month
    $y = date("Y",time());//get current year
    if ($m == 9) { $y + 2; }
    else if ($m == 10) { $y + 2; }
    else if ($m == 11) { $y + 2; }
    else if ($m == 12) { $y + 2; }
    else { $y + 1; }

    $expires = mktime(0,0,0,1,1,$y);

    $expires would now be the expiration time
    in "Unix" Epoch seconds for placement in the
    applications database.

    Granted it may also work to just do:
    if ($m >= 9) { $y + 2; }
    else { $y + 1; }

    etc..

    what do you think?

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    43
    Rep Power
    15
    Actually yes that simplifies it even further. Plus the epoch time is easier to compare to the current time since it's a single value. So if you launch a daemon with crontab for daily checking.

    if($dbepochtime <= time()) {
    //send notification for renewal etc.
    }

    of course you may want to send notification ahead of time.
  10. #6
  11. No Profile Picture
    Robert_J_Sherman
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks for the assist..

    you certianly helped get me on the right track, and think it through.

    ------------------
    SnR Graphics,
    Low Cost Hosting and Web Development.

IMN logo majestic logo threadwatch logo seochat tools logo