/    Sign up×
Community /Pin to ProfileBookmark

comparison of date with PHP

is there anyway i can compare 3 or more date type column?

let’s say i have
————————————————


date1 | date2 | date3
————————————————


2006-06-01 | 2006-06-15 | 2006-09-19
————————————————

and my select statement returns this 3 value.

is there any way i can write in PHP to get the earliest or the latest date?
let’s say:

[code]
$earliest = XXX($row[date1], $row[date2], $row[date3]) <- returns (“2006-06-01”)

$latest = XXX($row[date1], $row[date2], $row[date3]) <- returns (“2006-09-19”)
[/code]

i tried to get these from mysql command like if possible but cant find any way to do it..
i guess there’s no function to this..
select XXXXX(date1,date2,date3) <–returns ‘2006-06-01 ‘
select YYYYY(date1,date2,date3) <–returns ‘2006-09-19 ‘

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@SheldonJul 28.2006 — This has come up so many times, Do a quick search and you will find the answers.
Copy linkTweet thisAlerts:
@PineSolPirateJul 28.2006 — I don't know much about mysql data types (spec. this "date" type) but if you stored the dates as time since unix epoch (uh, unix timestamp) or just in this fashion YYYYMMDD you could use array_sort on the values then take the first and last index ( [0] & [-1]) as the two choice dates.

Did that make any sense?

Otherwise I guess you could use substr on them and do the same thing without changing the db any.
Copy linkTweet thisAlerts:
@reiauthorJul 28.2006 — Sheldon,

thanks, maybe i just searched with the wrong keyword.... T.T

PineSolPirate,

thanks! i got what u meant!

by the way, my data is "YYYY-MM-DD" so i can sort it as u said
Copy linkTweet thisAlerts:
@PineSolPirateJul 28.2006 — Cool, I didn't know if the dashes would screw it up. Now I know more ?
×

Success!

Help @rei 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.28,
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,
)...