user2228185 user2228185 - 5 months ago 10
PHP Question

PHP Check if date is past in the format 10-08-2015

I'm trying to check if the specific given date is past or not with PHP, I cannot change the date format as there are thousands of records like this in the database.

$actdate = '10-08-2015';


The format is day-month-year

Thank You

Edit: Get it working, thanks to Aruna Warnasooriya.

$actdate = "10-08-2015";
$yourdate = date_create(date($actdate));
$mydate = $yourdate->format("Y-m-d");
$date = new DateTime($mydate);
$now = new DateTime();

if($date < $now) {echo 'date is in the past';} else {echo 'date is not in the past'; }

Answer

PHP :

$today = date("d-m-Y");

you can create a date using date_create function.This will create data object.

$actdate = "10-08-2015";
$yourdate = date_create(date($actdate));

format your date as you wish.like this;

echo $yourdate->format("d-m-Y");
Comments