Comapring Dates
Posted: Tue Jul 14, 2009 2:54 pm
Hi, I have a problem of comparing a time that comes from a field in Microsoft Access database versus the current time on PC using the php date() function.
I have tried several things already but it seems that Microsoft time format is presented in some weird way and doesn't compare to php format. What I wanted to do is to display certain fields from the database ont he condition that their time is bigger then the current PC time.
<?php
date_default_timezone_set("America/Montreal");
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
// Microsoft Access connection string.
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\\Inetpub\\wwwroot\\MeetingSystemTest\\Meetingsystem\\meeting.mdb");
$rs = $conn->Execute("SELECT Event.Time, Event.Meeting, Event.Room, Event.Date FROM Event");
if ($rs->EOF)
{
echo "empty";
}
else
{
while (!$rs->EOF) {
if($rs->Fields("Date") == date("n/j/Y"))
{
$time = $rs->Fields("Time");
if ($time > date("H:i A"))
{
echo "Value: ".$rs->Fields("Time")->Value;
echo " ".$rs->Fields("Meeting")->Value;
echo " ".$rs->Fields("Room")->Value."<br>\n";
}
}
$rs->MoveNext();
}
}
$rs->Close();
echo date("n/j/Y"). " " .date("g:i A");
/*as Event WHERE Event.Date = " .date("n/j/Y"). " AND Event.Time > #" .date("g:i A"). "# ORDER BY Event.Time"*/
?>
There seems to be no problem with date comparing, but time doesn't work for me. It seems that it ignores the AM/PM difference.
Anybody has any suggestions?
I have tried several things already but it seems that Microsoft time format is presented in some weird way and doesn't compare to php format. What I wanted to do is to display certain fields from the database ont he condition that their time is bigger then the current PC time.
<?php
date_default_timezone_set("America/Montreal");
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
// Microsoft Access connection string.
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\\Inetpub\\wwwroot\\MeetingSystemTest\\Meetingsystem\\meeting.mdb");
$rs = $conn->Execute("SELECT Event.Time, Event.Meeting, Event.Room, Event.Date FROM Event");
if ($rs->EOF)
{
echo "empty";
}
else
{
while (!$rs->EOF) {
if($rs->Fields("Date") == date("n/j/Y"))
{
$time = $rs->Fields("Time");
if ($time > date("H:i A"))
{
echo "Value: ".$rs->Fields("Time")->Value;
echo " ".$rs->Fields("Meeting")->Value;
echo " ".$rs->Fields("Room")->Value."<br>\n";
}
}
$rs->MoveNext();
}
}
$rs->Close();
echo date("n/j/Y"). " " .date("g:i A");
/*as Event WHERE Event.Date = " .date("n/j/Y"). " AND Event.Time > #" .date("g:i A"). "# ORDER BY Event.Time"*/
?>
There seems to be no problem with date comparing, but time doesn't work for me. It seems that it ignores the AM/PM difference.
Anybody has any suggestions?