Jump to content

Dates


mikeroq

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/6158-dates/#findComment-22212
Share on other sites

[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
Link to comment
https://forums.phpfreaks.com/topic/6158-dates/#findComment-22215
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.