/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Comparing Time

I am trying to make a list that will only show events that have happened. The event is put in by month day and year. Here is my code:

[code=php]
$todaysdate = strtotime(‘now’);
$sql = “SELECT * FROM cle”;
$result=mysql_query($sql) or die(“Couldn’t execute query: “.mysql_error());
while ($rows=mysql_fetch_array($result)) {
$month = $rows[‘month’];
$day = $rows[‘day’];
$year = $rows[‘year’];
$cutoffdate = strtotime($month/$day/$year);

if($cutoffdate <= $todaysdate){
echo ‘<tr><td>’.$topic.'</td></tr>’;
} else {
echo “”;
}
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@beylahauthorJan 20.2014 — $cutoffdate = "$month/$day/$year";

if(strtotime($cutoffdate) < strtotime('now')) {
Copy linkTweet thisAlerts:
@rootJan 20.2014 — Even simpler would be store dates as a time reference so you have both a time frame and a date, this being similar to the JavaScript new Date().getTime() which is a reference in milliseconds.

Any future comparison will be based on a simple X < Y test.
×

Success!

Help @beylah 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...