user4fun Posted December 29, 2006 Share Posted December 29, 2006 how do i compare dates in phpexampleafter the $Edate ( meant to be Experiation Date) value is extracted from a sql serveri want to if current date (today) is after the $Datethen echo EXPIREDif current date( today) = $Datethenecho membership will end todayone or two more if statmentselseecho Status is valid untill $Dateecho ($Date - Current Date) XXX the different between the two date in days.If this seems to be too much, feel free to pinch at it and just pick a peice and toss in your two cents. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 2, 2007 Share Posted January 2, 2007 Whenever I work with dates I always use timestamps. Timestamps are just integers. You can use timestamps measured in either seconds or milliseconds, and it's from a certain date. Unix timestamps are the time since 1/1/1970. PHP timestamps are also from that date, but are measured in seconds by default.So, once the dates are all just numbers, you can add and subtract them to compare them. You can add several days to one or whatever. You can subtract them, and then divide the difference by (60*60*24) to get the number of days apart they are.This is how you get the current timestamp:http://www.php.net/manual/en/function.time.phpConvert a timestamp to an array of usable information:http://www.php.net/manual/en/function.getdate.phpGet a timestamp for a specific date:http://www.php.net/manual/en/function.mktime.phpAnd format a timestamp for printing:http://www.php.net/manual/en/function.date.php Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now