/    Sign up×
Community /Pin to ProfileBookmark

comparing dates

I need to know how to compare a date with a text string taken from a flat-file. The flat-file will contain a date string (in whatever format is required) and it needs to be compared with the current date, if the current date is past the one in the file it will delete the file. I can code the second part, its the first part im having problems with.

I’d play with all of PHP’s different date settings buy my server has gone tits up at the mo so i thought it would be easier to ask you guys!

Thanks…

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@pyroJun 11.2003 — Something like this should be close...

[code=php]<?PHP

$date = "06-11-2003";

$today = date("m-d-Y"); #return today's date as MM-DD-YYYY

if ($today == $date) {
echo '$today is the same as $date';
}
else {
echo '$today is not the same as $date';
}

?>[/code]
Copy linkTweet thisAlerts:
@nutheadauthorJun 11.2003 — thanx pyro but it needs to be if it's equal or greater than today's date, thats what i cant work out.
Copy linkTweet thisAlerts:
@pyroJun 11.2003 — A bit tougher, but not too bad...

[code=php]<?PHP

$today = time(); #today's date in seconds since January 1, 1970
$date = "06-11-2003";
$d = split("-",$date);
$date_seconds = mktime(0,0,0,$d[0],$d[1],$d[2]); #turn $date into seconds since January 1, 1970
if ($today > $date_seconds) {
echo ("Delete the file");
}
else {
echo ("Don't delete the file");
}

?>[/code]
Copy linkTweet thisAlerts:
@nutheadauthorJun 11.2003 — You the man pyro! ?

[i]Originally posted by pyro [/i]

[B]A bit tougher, but not too bad...



[code=php]<?PHP

$today = time(); #today's date in seconds since January 1, 1970
$date = "06-11-2003";
$d = split("-",$date);
$date_seconds = mktime(0,0,0,$d[0],$d[1],$d[2]); #turn $date into seconds since January 1, 1970
if ($today > $date_seconds) {
echo ("Delete the file");
}
else {
echo ("Don't delete the file");
}

?>[/code]
[/B][/QUOTE]
Copy linkTweet thisAlerts:
@pyroJun 11.2003 — Thanks... ?
Copy linkTweet thisAlerts:
@tosbournAug 04.2006 — Just found this on Goggle when having the same problems - pyro - over 2 years on and you are still the man.
Copy linkTweet thisAlerts:
@hartnellOct 26.2006 — Same issue - found this via Google and had to register just to say thanks - worked as it should!
×

Success!

Help @nuthead 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.25,
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,
)...