Jump to content


Photo

Dates


  • Please log in to reply
4 replies to this topic

#1 mikeroq

mikeroq
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 March 2006 - 06:05 AM

I was wondering how I would have a function tell me if a date is before another date or after like
like 3/16/05 before 3/16/06 or 3/12/06 before 4/12/06

thanks

#2 nikhilthecool

nikhilthecool
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 30 March 2006 - 06:39 AM

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.

#3 mikeroq

mikeroq
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 March 2006 - 06:58 AM

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;
                            }
                    }
            }
        
    }
ive got most of it done

#4 flash gordon

flash gordon
  • Members
  • PipPipPip
  • Advanced Member
  • 150 posts

Posted 30 March 2006 - 07:14 AM

for heaven sakes get rid of that code! and use the Unix timestamp and date function.


#5 mikeroq

mikeroq
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 30 March 2006 - 05:03 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users