D
D
Danny132020-05-07 13:39:26
PHP
Danny13, 2020-05-07 13:39:26

How to show difference between today's date and date from database?

Unable to show the difference between today's date and the date from the database, which are displayed as jobs.

/*Здесь две переменные для начальной и конечной даты*/  
$starting_date = date("Y-m-d", strtotime($_POST['starting_date']));
$end_date = date("Y-m-d", strtotime($_POST['end_date']));
/*Здесь я беру значения переменных из определенного задания*/  
$dateStart = new DateTime($row['starting_date']);
$dateEnd =  new DateTime($row['end_date']);
/*Здесь я обозначаю сегодняшнее число*/
$currentDateTime = date('d-m-Y');
/*Здесь я считаю разницу между конечной датой и сегодняшним числом*/
$dateDifference = $dateEnd->diff($currentDateTime)->format('%a');


But for some reason the code doesn't work...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ildar Saribzhanov, 2020-05-07
@Danny13

Replace

/*Здесь я обозначаю сегодняшнее число*/
$currentDateTime = date('d-m-Y');

on the
/*Здесь я обозначаю сегодняшнее число*/
$currentDateTime = new DateTime();

And questions remain about the correctness of the date formats inside $_POST

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question