jeudi 28 janvier 2016

if condition fo show Year, Month, Days

Dear all,

I am a outside for the code writing, I have the below code is working.

<?php
$datetime1 = new DateTime("$date_of_dissolution");
$datetime2 = new DateTime("$date_of_incorp");
$difference = $datetime1->diff($datetime2);
echo 'And the company is running: '.$difference->y.' years, '.$difference->m.' months, '.$difference->d.' days.';
?>

But I want to add one more condition, but the below code is not working.

<?php
$datetime1 = new DateTime("$date_of_dissolution");
$datetime2 = new DateTime("$date_of_incorp");
$datetime3 = new DateTime("$date_commenced_dormancy");
$datetime4 = date("Y-m-d");

if ($active_status ==('Live but Commenced Dormancy')) {
$difference = $datetime3->diff($datetime2);
} elseif  ($active_status ==('Dissolved')) {
$difference = $datetime1->diff($datetime2);
} else {
$difference = $datetime4->diff($datetime2);

echo 'And the company is running: '.$difference->y.' years, '.$difference->m.' months, '.$difference->d.' days.';
?>

How should I modify the above code ? Thank you very much for your help & support !

Aucun commentaire:

Enregistrer un commentaire