Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts

    determine length of time to date

    Hello all, I'm trying to figure out how many days there are to an annual date (e.g., I need to know whether I'm approaching a yearly invoice date). The approach seems simple, but I've not been able to figure out this 'logic' problem. I assume this task needs to account for the year of the invoice date and today's date. Then it seems as though I just need to determine the number of days between those two dates once the year has been taken out of the equation.

    If anyone could be of assistance, I'd apprecdiate it.

    Thanks,

    Ryan

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,017
    Thanks
    2
    Thanked 313 Times in 305 Posts
    So long as your dates are within a range that can be represented using a UNIX timestamp (13 Dec 1901 (or 01-01-1970 on some op sys/php ver) to 19 Jan 2038), the easiest way is to get both the start and end date in terms of a timestamp (seconds), subtract the two to give the number of seconds difference, and do the division to give the number of days this corresponds to.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New Coder
    Join Date
    Jan 2005
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, I should have been more clear with my objective. In my admin area, I enter the creation date for a client. This date includes the month, day, and year of the creation date. I want this creation date to also serve as an annual reminder of when to invoice each client. For example, with a creation date of March 3, 2005, I want to receive a reminder to invoice that client EVERY year 30 days prior to March 3 even though the creation/invoice date does not change.

    Thanks,

    Ryan

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,017
    Thanks
    2
    Thanked 313 Times in 305 Posts
    You need to be even more specific, what format are you storing the date as and is this in a database (if so what kind.)
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New Coder
    Join Date
    Jan 2005
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry, currently, dates are stored in the following format: YYYY-MM-DD

    If need be, I can always store this date in the timestamp format.

    Thanks,

    Ryan

  • #6
    New Coder
    Join Date
    Jan 2005
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    So as I see it, the problem lies in the fact that the creation/invoice date is a static value derived from a database. Thus, the year on this date never changes. However, time moves on...and the year of the current date increases.

    Simply put, my question is how do I disregard year and determine the number of days between now and the creation/invoice date? For example, how many days are between March 4 and October 1 (of no specific year)?

    Thanks,

    Ryan

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    This will tell you how many days are left until the next invoice date:
    PHP Code:
    <?php
    $datetime 
    '2007-03-03';
    list(,
    $month$day) = explode('-'$datetime);

    $days_left = (mktime(0,0,0,$month$daydate('Y')) < time()) ? round((mktime(0,0,0,$month$daydate('Y') + 1) - time()) / (60 60 24)) : round((mktime(0,0,0,$month$daydate('Y')) - time()) / (60 60 24));
    echo 
    $days_left;
    ?>
    Last edited by Inigoesdr; 03-05-2007 at 01:03 AM.

  • #8
    New Coder
    Join Date
    Jan 2005
    Posts
    62
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Inigoesdr,

    Thanks so much! That code worked perfectly! As I suspected, this was a little beyond my skill level, but I have definitely learned from your code.

    Thanks for helping to keep this such a great forum!

    Ryan

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You're very welcome. =]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •