php date compare [duplicate]

Posted on

php date compare [duplicate] – Here in this article, we will share some of the most common and frequently asked about PHP problem in programming with detailed answers and code samples. There’s nothing quite so frustrating as being faced with PHP errors and being unable to figure out what is preventing your website from functioning as it should like php and date . If you have an existing PHP-based website or application that is experiencing performance issues, let’s get thinking about php date compare [duplicate].

I am newbe to php. I have small problem to compare dates in php.

I have 4 dates named date1, date2, start_date and end_date in the format yyyy-mm-dd.

i need the functionality like this:

if((date1>=start_date) && (date2<=end_date)){

} 

please help me to solve this.

Solution :

use strtotime to get the timestamps of your dates – this can be easily compared to each other like you already trying it.

If you have PHP 5.3, this is easily handled by the DateTime and DateDiff classes. If you have not, it is much harder, but look at the ‘user contributed’ section on DateDiff in the online PHP manual.

Leave a Reply

Your email address will not be published. Required fields are marked *