Previous 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
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Previous Dates

Post by iknownothing »

Hello all,
OK I'm building an administration page on one of my site. It pulls all items from a particular table in the database, and highlights items which are deadlined for the current date, but i would also like to highlight ALL previous dates indicating that it is overdue.

the closest way that i can think of (although not right), would be:

Code: Select all

if ($day == date("d")--){
...do highlight thing...
}
else {
...do nothing...
}
thanks.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: Previous Dates

Post by timvw »

iknownothing wrote:It pulls all items from a particular table in the database, and highlights items which are deadlined for the current date, but i would also like to highlight ALL previous dates indicating that it is overdue.
How are the dates stored in your database? (the column type??)

In the most simply case you would use the < (smaller than comparision operator)
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

i have set it up so that the day, month and year are in separate columns Integer type), probably not the best way to do it but its the way I did it.

So, I take it I implement the < like so (for example):

Code: Select all

$currentdate = date("dmy");

$completiondated = row ['compd'];
$completiondatem = row ['compm'];
$completiondatey = row ['compy'];

$date =  $completiond . $completionm . $completiony;

if ($currentdate > $date) {
...do thing...
}
else {
...do nothing...
}
I would test it out for myself but the original code isnt right in front of me at the moment and figured I'd make sure I'm right before I spend more hours trying to figure out what the hell I'm doing...

Thanks for your help too...
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

iknownothing wrote:i figured I'd make sure I'm right before I spend more hours trying to figure out what the hell I'm
In that situation i would recommend to read a tutorial about php and mysql.. eg: you're comparing a date ($currentdate) against a string ($date)...
Post Reply