date function

Discussion in 'PHP' started by lomaxman, Mar 26, 2010.

  1. #1
    Hi guys,

    Ok,im new to functions and yet trying getting my head around them.

    Why does this code work :

    <?php
    $start_date = '2010-02-27 11:50';
    $end_date = '2010-03-05 11:50';
    $seconds = strtotime($end_date) - strtotime($start_date);
    $days = floor($seconds / 86400);
    echo "The difference is {$days} days.<br>";
    ?>
    Code (markup):
    and this function doesnt ?

    <?php
    function getDays($start_dat,$end_date)
    	{
    		$seconds = strtotime($end_date) - strtotime($start_date);
    		$days = floor($seconds / 86400);
    		return $days;
    	}
    
    $start_date = '2010-02-27 11:50';
    $end_date = '2010-02-28 11:50';
    
    echo getDays($start_date,$end_date);
    ?>
    Code (markup):
    Any comments are welcome
     
    lomaxman, Mar 26, 2010 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    When posting questions specific to code not working always post any errors you get and/or actual results vs. expected results. For your specific issue, you forgot the 'e' on $start_date when you declared the function:

    function getDays($start_dat,$end_date)
     
    plog, Mar 26, 2010 IP
  3. lomaxman

    lomaxman Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    oh my,thank you, i guess i should go and get some sleep :p
    regarding code questions, i will have that in mind !
     
    lomaxman, Mar 26, 2010 IP
  4. ghprod

    ghprod Active Member

    Messages:
    1,010
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    78
    #4
    Lol, mistype ... this is common mistake for programmer ..
     
    ghprod, Mar 26, 2010 IP