SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need to find pro-rated price ($today - 2007-12-31) / (number of days in year)

    I am trying to get a pro-rated subscription price based on when they sign up.

    I order to get the number of days between today and the end of the year, I first have to know I need to get the number of days in THIS year - since there are leap years.

    I think this code will work for getting the #days between now and end of year:
    PHP Code:
    $year_end Year(date())."-12-31";
    $date_diff roundabs(strtotime(date('y-m-d'))-strtotime($year_end)) / 86400); 
    I still need help getting the # days in whatever year we are in.

    Any ideas besides calling the easy MySQL DATEDIFF() function?

    something like:
    ($date_diff/(total number of days this year)) * pricing

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I understand, you're looking for:
    Code:
    # days of service/# days in year
    Yes? Try this:
    PHP Code:
    $today date('z');
    $year_end date('z'strtotime("31 December $year"));
    $prorate = ($today-$year_end)/$year_end
    Still not entirely sure I understand what exactly you're looking for, but this may point you where you need to go at least.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    $num_day 
    date('z'strtotime("31 December $curr_year")); # find number of days in the current year
    $days_left $num_day date('z'); # number of days left

    $per_day $full_year_fee $num_day# find out how much it costs per day
    $prorated_fee $per_day $days_left;

    # might be off by a day 

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    USA
    Posts
    1,407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    many thanks for your help - got it working


Bookmarks

Posting Permissions

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