Search code examples
phpdateyii2comparisonstrtotime

php strtotime funtion is not giving output


I am using strtotime() function to compare two dates, one is today and second from DB, It was working fine some days ago but today its not working Here is the code

$today=strtotime(date("d-M-Y H:i A"));
$registration_start_date=strtotime($model->registration_start_date);

in this code there is no output for $today even I have tried to echo just date and date was printed out but when I kept date("d-M-Y H:i A") in strtotime its empty, even $registration_start_date=strtotime($model->registration_start_date); is giving proper output. kindly help out. Thanks


Solution

  • This is what happens with date now:

    php > echo date("d-M-Y H:i A");
    30-Jun-2020 17:29 PM
    

    17:29 PM?

    Just remove A from date format, you use H - this is already 24 hour format:

    php > var_dump(strtotime(date("d-M-Y H:i A")));
    bool(false)
    php > var_dump(strtotime(date("d-M-Y H:i")));
    int(1593531060)
    

    Maybe this code works before noon but i wouldn't count on it.