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?
Comapring Dates
Moderator: General Moderators
Re: Comapring Dates
Have you tried using the time in 24-hour format?
Re: Comapring Dates
yup tried every format pretty much always does the same thing. for me it looks like it's comparing only the first number in the whole time string.
Re: Comapring Dates
What is the output of $rs->Fields("Date") and $rs->Fields("Time") ?
Re: Comapring Dates
Time: 2:00:00 PM Date: 7/14/2009Skara wrote:What is the output of $rs->Fields("Date") and $rs->Fields("Time") ?
Time: 9:30:00 AM Date: 7/14/2009
Time: 1:30:00 PM Date: 7/14/2009
Time: 3:30:00 PM Date: 7/14/2009
Time: 7:30:00 AM Date: 7/14/2009
Time: 7:30:00 AM Date: 7/14/2009
Time: 10:30:00 AM Date: 7/14/2009
Time: 8:00:00 AM Date: 7/14/2009
Re: Comapring Dates
So from what I understand, this is the problem?: if ($time > date("H:i A"))
try
try
Code: Select all
$time = strtotime($rs->Fields('Date') . ' ' . $rs->Fields('Time'));
if ($time > time()) {Re: Comapring Dates
it works.
damn should've though about it.
Thx a lot. Really apreciated.
damn should've though about it.
Thx a lot. Really apreciated.