I wish that when receiving an email after it passes 24hrs it shows the date and not the time ago as per the image

Asked

Viewed 20 times

-2

I’m using the : briannesbitt/Carbon

I use this code to render what I wish

<?= \Carbon\Carbon::create($mail->created_at)->locale('pt')->diffForHumans(); ?> atrás

The same prints equal to the image below:

Gerenciador de e-mail

What I wish is the following: After 24 hours the email arrives in the inbox, the same print the creation date instead of "1 day ago" or "1 week ago" in case the "1 hour ago" is correct, and what is stated "1 week ago", should be the creation date example 17/02/2021.

  • Makes a if. If it is less than 24 hours, you show the diffForHumans, otherwise shows the formatted date.

  • Thanks, boy I’m new with dates, I’m learning, now that I found out about Carbon.

1 answer

0


Just implement a condition that checks if the difference is greater than 24h. Something like this:

$diff = \Carbon\Carbon::create($mail->created_at)->locale('pt');

if ($diff->diffInHours() > 24) {
  echo $diff->format("d/m/Y H:i:s");
} else {
  echo $diff->diffForHumans();
}
  • thanks stayed the way I wanted

Browser other questions tagged

You are not signed in. Login or sign up in order to post.