Results 1 to 2 of 2

Thread: php calendar

  1. #1
    Join Date
    Nov 2006
    Posts
    249

    php calendar

    I am having problems with a php calendar that reads from a mysql database. The site has been transfered from a different server and now does not seem to work properly. i get the error message.

    Warning: date(): Windows does not support dates prior to midnight (00:00:00), January 1, 1970 in C:\Inetpub\vhosts\saukvalleyareachamber.com\httpdocs\calendar\includes\functions.php on line 23

    This is the code that seems to be the problem.

    Code:
    
    
    
    
    
    
    <!-- Functions.php -->
    
    
    
    
    
    
    
    
    <?php
    
    function fixdate($month,$day,$year)
      {
    			$dateToFix="$year-$month-$day";
                $unixTime=mktime($dateToFix);
                $fixedDate=date("Y-m-d",$unixTime);
    			return $fixedDate;
      }
    
    
    
    function fixtime($hour,$minute,$second,$ap)
      {
    			$time="$hour$minute$ap";
    			if ($time=="120AM")
    			  {$fixedTime="12:00:00 AM"; return $fixedTime;}
    			elseif($time=="120PM")
    			{$fixedTime="12:00:00 PM"; return $fixedTime;}
    			else{
    			if ($ap=="PM"){$hour=$hour+12;}
    			
    			$timeToFix="$hour:$minute:$second";
                $unixTime=strtotime($timeToFix);
                $fixedTime=date("h:i:s A",$unixTime);
    			return $fixedTime;
    			}
      }
    line 23 is
    $fixedDate=date("Y-m-d",$unixTime);

    Can anyone tell me what might be the problem?

  2. #2
    Join Date
    Feb 2007
    Location
    Ireland
    Posts
    1,007
    The problem is the Unix timestamp. A Unix timestamp is a linear representation of time in seconds from the 1st of January, 1970 (00:00).

    Code:
    function fixdate($month,$day,$year)
    { 
    	$dateToFix="$year-$month-$day";
            $unixTime=mktime($dateToFix);
            $fixedDate=date("Y-m-d",$unixTime);
            return $fixedDate;
    }
    Your $dateToFix var concatenates the 3 variables together, however the function your using to convert them to a Unix timestamp contains the wrong number of parameters. To do what your doing, you should use the strtotime() function. Check it out here http://www.php.net - strtotime function

    The error your getting is caused because the function (mktime) can't understand the input variable ($dateToFix) and it thinks its a date before the Unix Epoch (1/1/1970).

    That strtotime() function should solve your problem. (",)
    “The best thing about a boolean is even if you are wrong, you are only off by a bit.”

Posting Permissions

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