SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast Donut's Avatar
    Join Date
    Nov 2001
    Location
    Brisbane, Australia
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding x days to a given date

    I'm having problems trying to add x days to a date given by the user.

    For instance if the user selects the date 2002-06-28, I want the script to be able to give the date of the following day. I googled on this but all the pages found only wanted to add a day to the current date, not a given date.

    Can anyone help me on this?

    Thanks in Advance
    Donut

  2. #2
    SitePoint Zealot jonsteele's Avatar
    Join Date
    Jan 2001
    Location
    Toronto
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    You could use the getdate() function.
    PHP Code:
    $a getdate(); //get current date info
    $addedOneDay mktime($a['hours'],$a['minutes'],$a['seconds'],$a['month'],$a['mday']+1,$a['year']); //create new timestamp and add one to day 

  3. #3
    SitePoint Enthusiast Donut's Avatar
    Join Date
    Nov 2001
    Location
    Brisbane, Australia
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But won't that just add one day to the current date?

    I want to add one day to a given date e.g. add one day to the 2002-06-28 to give 2002-06-29.

  4. #4
    SitePoint Enthusiast menkes's Avatar
    Join Date
    Jul 2002
    Location
    Channel Islands
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, the above post will just add one day to today. But you just need to substitute your date. You can do something like this:

    PHP Code:
    $dt "2002-07-11";
    $parts explode("-"$dt);

    $tomorrow  date("Y-m-d",mktime (0,0,0,date("$parts[1]")  ,date("$parts[2]")+1,date("$parts[0]"))); 
    Hope that helps...

  5. #5
    SitePoint Enthusiast Donut's Avatar
    Join Date
    Nov 2001
    Location
    Brisbane, Australia
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Fantastic, works perfectly!

    Thanks alot for that Menkes.

  6. #6
    SitePoint Zealot jonsteele's Avatar
    Join Date
    Jan 2001
    Location
    Toronto
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    getdate can take a parameter...

    getdate($whateverTimeStampYouWant);


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
  •