Comapring Dates

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Comapring Dates

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Comapring Dates

Post by requinix »

Have you tried using the time in 24-hour format?
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Re: Comapring Dates

Post 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.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Comapring Dates

Post by Skara »

What is the output of $rs->Fields("Date") and $rs->Fields("Time") ?
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Re: Comapring Dates

Post 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
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Comapring Dates

Post 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()) {
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Re: Comapring Dates

Post by kaosalrim »

it works.
damn should've though about it. :banghead:
Thx a lot. Really apreciated.
Post Reply