mikeroq Posted March 30, 2006 Share Posted March 30, 2006 I was wondering how I would have a function tell me if a date is before another date or after likelike 3/16/05 before 3/16/06 or 3/12/06 before 4/12/06thanks Quote Link to comment https://forums.phpfreaks.com/topic/6158-dates/ Share on other sites More sharing options...
nikhilthecool Posted March 30, 2006 Share Posted March 30, 2006 get the date in a variable using the date('Y','M','d') or something like that.pass the variable and also the current date variable to the function .Inside the function, jus subtract both variables.If result>0, the date is greater and otherwise.This is jus my way of implementing it. you can have a lot other ways. Quote Link to comment https://forums.phpfreaks.com/topic/6158-dates/#findComment-22212 Share on other sites More sharing options...
mikeroq Posted March 30, 2006 Author Share Posted March 30, 2006 [code]function addates($date1) { // date1 is when it expires $date2 = date("n/j/Y"); $date1 = explode("/",$date1); $date2 = explode("/",$date2); $month1 = $date1[0]; $day1 = $date1[1]; $year1 = $date1[2]; $month2 = $date2[0]; $day2 = $date2[1]; $year2 = $date2[2]; if ($year1 < $year2) { // if the expires year is less the current year, toss it out return false; } else if ($year1 == $year2) { // if the expires year is the same as this year, then we will check month if ($month1 > $month2 && $year1 == $year2) { // if the current month is before the expired month, and the year is the same, go ahead return true; } else if ($month1 < $month2 && $year1 == $year2) { // if the current month is after the expired month, toss it out return false; } else if ($month1 == $month2 && $year1 == $year2) { // check to see if day is before or after current if ($day1 = $day2 || $day1 > $day2) { return true; } else ($day1 < $day2) { return false; } } } }[/code]ive got most of it done Quote Link to comment https://forums.phpfreaks.com/topic/6158-dates/#findComment-22215 Share on other sites More sharing options...
flash gordon Posted March 30, 2006 Share Posted March 30, 2006 for heaven sakes get rid of that code! and use the Unix timestamp and date function. Quote Link to comment https://forums.phpfreaks.com/topic/6158-dates/#findComment-22218 Share on other sites More sharing options...
mikeroq Posted March 30, 2006 Author Share Posted March 30, 2006 wait a min, why was I doing regular dates anyway!, almost everything on my site uses the unix time stamp, hahahahahahahaha. thats what midnight does to you Quote Link to comment https://forums.phpfreaks.com/topic/6158-dates/#findComment-22345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.