www.webdeveloper.com
Results 1 to 3 of 3

Thread: How to get End Date from Adding Start Date with Duration Count?

  1. #1
    Join Date
    Jul 2013
    Posts
    1

    How to get End Date from Adding Start Date with Duration Count?

    I have table which has the table field name:
    - Start Date
    - Duration Count (e.g. 1, 2 or 3)
    - Duration Name (e.g. Daily, Monthly, Yearly)
    - End Date

    How do I code in PHP to calculate the end date from a particular start date?

    E.g. The start date is on 1st January 2013, and duration count is 1, duration name is yearly.
    Which actually meant to be 1 year duration. How do I code in order to get the answer of
    31st December 2013 in my end date column?

    Example Formula: $StartDate + $DurationCount & $DurationName = $EndDate?

    Noticed that I'm facing the problem when it comes to monthly issues. For example is an invoice bill
    starts on 31st January 2013, after one month the bill supposed to be due in March. It matters when
    whether 2013 is a lear year or non leap year.

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,205
    http://php.net/manual/en/ref.datetime.php


    PHP Code:
    $nextWeek date('Y-m-d'strtotime('+1 week'));

    echo 
    $nextWeek
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    Just to expand a bit on the above example (because it's lunch time ):
    PHP Code:
    $StartDate $DurationCount $DurationName $EndDate?
    $endDate date('Y-m-d 00:00:00'strtotime("+$durationCount $durationName"strtotime("$startDate 00:00:00"))); 
    (untested)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles