April 26, 2012

Finding whether time is in a defined range

Question by spsingh

Possible Duplicate:
How to check if a date is in a given range?
How to check if date(entered by user) is in given range (Date format :-day month ie.:-1 june )

I am trying to find whether a date is in defined range. I’m using the following code:

    $apple='25 March';
    $udate= date('d F',strtotime($apple));

    echo $udate;
    $startDate='21 March';
    $realStartDate= date('d F',strtotime($startDate)) ;
    echo $realStartDate;
    $endDate='19 April';
    $realEndDate= date('d F',strtotime($endDate)) ;
    if ($udate >= $realStartDate && $udate <= $realEndDate ) {
        echo 'within tange';
    }
    else{
        echo 'Not in range';
    }
    ?>

Where am I going wrong?

Answer by Starx

Like this

if(strtotime($givendate) > strtotime('3/21/xxxx') && strtotime($givendata) < strtotime('4/19/xxxx')) {
   // Its within range
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!