Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MahmoudAdelAli's avatar

Comparison between 2 times with PM and AM

Hi , before 2023 i use this condition to check if the task expired or not

 @if($task->expire_date > date('Y-m-d') || $task->expire_date == date('Y-m-d') && $task->expire_at_time > date('h:i A'))
                    <span class="badge badge-danger" data-toggle="tooltip" data-placement="top"
                          title="{{$task->expire_date}}">
                         <i class="la la-close"></i>
                          Expired
                      </span>

                  @else
                    <span class="badge badge-info">
                     <i class="la la-calendar-check-o"></i>
                    {{$task->expire_date == date('Y-m-d') ? "Today" : $task->expire_date}}
                  </span>
                    <span class="badge badge-warning">
                      <i class="la la-clock-o"></i>
                        {{$task->expire_at_time}}
                  </span>
                  @endif

but for some reason today all tasks is expired , so i decided to check the expire at time and date to know where's the problem

{{dd($task->expire_at_time)}}
"02:07 PM"
{{dd(date('h:i A'))}}
"12:26 PM"

so i make comparison

{{dd($task->expire_at_time > date('h:i A'))}}
false

and i don't know how the 12:26 Pm grater than the 02:07 PM and before any thing i use date format cause i prepare it at the model as attribute

 public function getExpireAtTimeAttribute(): string
  {
    return date("h:i A", strtotime($this->expire_time));
  }

  public function getDueAtTimeAttribute(): string
  {
    return date("h:i A", strtotime($this->due_time));
  }

  public function getExpireTimeIsAttribute()
  {
    return Carbon::parse($this->expire_time)->format('H:i');

  }

so how i can check the tasks expired or not and where's the problem ?

0 likes
3 replies
jlrdw's avatar

Unless I misread, use the entire datetime all at once to compare.

jorgensolli's avatar
Level 4

Casting expire_time to carbon would make it easier for you.

Then you can simply validate if the task has expired or not by doing $task->expire_date->isPast()

1 like
newbie360's avatar

another one can use $task->expire_date->isToday()

1 like

Please or to participate in this conversation.