/    Sign up×
Community /Pin to ProfileBookmark

comparing dates

In my code I would like to compare a date held in a MYSQL table with the current date.

The name of the field is ‘dateAdded’, the datatype for this field is DATE, format 0000:00:00

Here in the UK we tend to use dd/mm/yyyy format.

I want a row of table to be displayed in RED if the dateAdded value is < todays date.

something like:

if dateAdded < date()
{
// print in red
}
else
{
// print in black
}

Not sure how to go about this though.

John

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachOct 18.2007 — [code=php]

if ($dateAdded <= date('Y:m:d') ) {

echo '<span style="color: #ff0000;">'.$dateAdded.'</span>';

}

else {

echo $dateAdded;

}


[/code]
Copy linkTweet thisAlerts:
@john_nobleauthorOct 18.2007 — Perfect

Thanks,

John
Copy linkTweet thisAlerts:
@stephan_gerlachOct 18.2007 — no problem
Copy linkTweet thisAlerts:
@ShaReBOct 19.2007 — stephan.gerlach, so what if $dateAdded is DateTime data type in the db?

and how to format the date from the db to be something like "September 12th, 2007"?

thanks in advance

~Shareb
Copy linkTweet thisAlerts:
@stephan_gerlachOct 19.2007 — something like this. probably wont work but i am sure you can figure it out from here

[code=php]

// split the datetime at the space
$parts = explode(' ',$dateAdded);

// split date at the :
$date_parts= explode(':',$parts[0]);

if ($parts[0] <= date('Y:m:d') ) {

echo '<span style="color: #ff0000;">'.date('F dS, Y',mkdate(1,1,1,$date_parts[1],$date_parts[2],$date_parts[0])).'</span>';

}

else {

echo $dateAdded;

}

[/code]
Copy linkTweet thisAlerts:
@ShaReBOct 19.2007 — Thanks, i got the idea..
×

Success!

Help @john_noble spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...