Results 1 to 2 of 2

Thread: [Resolved] DateDiff problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    Resolved [Resolved] DateDiff problem

    Hello all. I found the following code which will display the number of days between two dates. The problem is if I take out the "SEP" and replace it with say 9 or 09 it doesn't work.
    How would I rewrite this so that I can use all numeric values.
    All the dates in my database use yyyy-mm-dd format if that helps.

    Code:
    $today=date("d-m-Y");
    $date1=strtotime( "1-SEP-2005");
    
    $date2=strtotime($today);
    
    	echo "Difference: ".(($date2-$date1)/86400);
    Many thanks.
    Last edited by solitario; Sep 21st, 2005 at 11:09 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    121

    Re: DateDiff problem

    Got it.
    Code:
    function datediff($start_date, $end_date) {
    	list($start_date_month, $start_date_day, $start_date_year) = split('[/.-]', $start_date); 
    		if (!$end_date) {
    			$end_date_year = date("Y");
    			$end_date_month = date("m");
    			$end_date_day = date("d");
    		} else {
    			list($end_date_month, $end_date_day, $end_date_year) = split('[/.-]', $end_date);
    		}
    			$start_date = mktime(0,0,0,$start_date_month, $start_date_day, $start_date_year);
    			$end_date = mktime(0,0,0,$end_date_month, $end_date_day, $end_date_year);
    			$difference = $end_date-$start_date;
    				return floor($difference/60/60/24);
    }

Posting Permissions

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



Click Here to Expand Forum to Full Width