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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.