How to format date and time values in Blade templates using Laravel's date directive?

To format date and time values in Blade templates using Laravel's date directive, you can follow these steps:

  1. Use the double curly braces {{ }} to output the value in the template.
  2. Inside the curly braces, use the @date directive followed by the date value you want to format.
  3. Specify the desired format using the PHP date function format codes.
  4. Place the format codes inside quotes and within the parentheses after the @date directive.

Here is an example of formatting a date and time value using Laravel's date directive in a Blade template:

{{ @date($yourDateValue, 'Y-m-d') }}

In this example, $yourDateValue can be any valid date and time value that you want to format, such as a column value from a database query result.

The format code 'Y-m-d' specifies the desired format. Here 'Y' represents the four-digit year, 'm' represents the two-digit month, and 'd' represents the two-digit day.

You can use various other format codes as per your requirements. For example, to display the date and time in a more readable format, you can use 'F j, Y \a\t g:i a', where 'F' represents the full name of the month, 'j' represents the day without leading zeros, 'Y' represents the four-digit year, 'g' represents the hour in 12-hour format without leading zeros, 'i' represents the minutes, and 'a' represents 'am' or 'pm'.

By following these steps and customizing the format codes, you can easily format date and time values in Blade templates using Laravel's date directive.