Page 1 of 1

Comapring Dates

Posted: Tue Jul 14, 2009 2:54 pm
by kaosalrim
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?

Re: Comapring Dates

Posted: Tue Jul 14, 2009 3:30 pm
by requinix
Have you tried using the time in 24-hour format?

Re: Comapring Dates

Posted: Tue Jul 14, 2009 3:33 pm
by kaosalrim
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

Posted: Tue Jul 14, 2009 3:35 pm
by Skara
What is the output of $rs->Fields("Date") and $rs->Fields("Time") ?

Re: Comapring Dates

Posted: Tue Jul 14, 2009 3:40 pm
by kaosalrim
Skara wrote:What is the output of $rs->Fields("Date") and $rs->Fields("Time") ?
Time: 2:00:00 PM Date: 7/14/2009
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

Posted: Tue Jul 14, 2009 3:45 pm
by Skara
So from what I understand, this is the problem?: if ($time > date("H:i A"))
try

Code: Select all

$time = strtotime($rs->Fields('Date') . ' ' . $rs->Fields('Time'));
if ($time > time()) {

Re: Comapring Dates

Posted: Tue Jul 14, 2009 3:57 pm
by kaosalrim
it works.
damn should've though about it. :banghead:
Thx a lot. Really apreciated.