1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

I need help with the date() function

Discussion in 'PHP' started by LaPoChE, Jul 26, 2006.

  1. #1
    Hey,

    i'm new to PHP and i'm having trouble with the date() function. I need to get todays date and the following 5 days after. it needs to be in the following format "mm/dd/yyyy".

    Can anyone help me out?

    thanks
     
    LaPoChE, Jul 26, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $unix_stamp = strtotime("now"); //today
    $unix_stamp = strtotime("+1 day"); //tomorrow
    echo date("m/d/Y", $unix_stamp);
    PHP:
     
    T0PS3O, Jul 26, 2006 IP
    coderlinks likes this.
  3. pierre

    pierre Active Member

    Messages:
    71
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    98
    #3
    http://www.php.net/date
    <?php
    //get timestamp for past/future date I want
    $pf_time = strtotime("+5 days");
    //format the date using the timestamp generated
    $pf_date = date("m/d/Y", $pf_time);
    echo $pf_date ;
    ?>
    Code (markup):
    this prints
    C:\Documents and Settings\User\regexp>php -f date.php
    07/31/2006
    C:\Documents and Settings\User\regexp>
    Code (markup):
     
    pierre, Jul 26, 2006 IP
    T0PS3O likes this.
  4. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #4
    This is another solution, is that clearer? In this ways, we can get exactly next/previous time (in seconds)

    
    <?
    $now=time(); // Current timestamp
    $nextFiveDay=$now+5*24*3600; // exactly next 5 day
    echo "Next five days: ".date("m/d/Y",$nextFiveDay);
    ?>
    
    PHP:
     
    goldensea80, Jul 26, 2006 IP