PDA

View Full Version : php calendar



Magiccupcake
09 Jan 2008, 03:43 PM
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.










<!-- 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?

Alan
30 Jan 2008, 02:59 PM
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).


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 (http://ie2.php.net/manual/en/function.strtotime.php)

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. (",)