There are three variables that contain these values:

$now=strtotime(date('dmY H:i')); $startdate = 10-04-2016 09:00; $finishdate = 15-05-2016 09:00; $finishdate = strtotime($finishdate); $startdate = strtotime($startdate); 

You need to write a condition that checks whether the current date is between the start date and the end date or not. Wrote as follows:

  if(($startdate<=$now) && ($now<=$finishdate)){ echo 'Начат'; }else{ echo "Не начат"; }; 

But this does not work, more precisely, all the time "not started"

  • one
    and did not try to use strtotime ? - BOPOH
  • @BOPOH, yes I didn’t even know about it, what it gives, all formats will lead to the right kind, which will be understandable for php? - Evgeny Shevtsov
  • @BOPOH tried, only the current date is converted, the dates in text format do not want to be converted. - Yevgeny Shevtsov
  • so it is necessary to specify the question, for example, when I do var_dump(strtotime('10-04-2016 09:00')); I get a normal result, which I can already verify with time() - BOPOH
  • it should be indicated in the question, I do the same thing as you, but everything is fine with me. If something is wrong with you, it means that you are doing something wrong, so you need to write what you are doing (and what is not) in the question, so that not only I saw it, but the rest did not have to read the comments - BOPOH

1 answer 1

The date and time string must be translated to the Unix timestamp using the strtotime function. And then compare, for example:

 $startdate = strtotime('10-04-2016 09:00'); $finishdate = strtotime('15-05-2016 09:00'); if (($startdate <= time()) && (time() <= $finishdate)) { echo 'Начат'; } else { echo 'Не начат'; }; 

Compare with time () , because time () returns the current time in Unix timestamp format.