django template date format yyyy-mm-dd
{{ my_date_variable|date:"Y-m-d" }}
Explanation:
- {{ my_date_variable }}
: This represents the variable containing the date value that you want to format.
- |date:"Y-m-d"
: This pipe symbol (|
) is used to apply a filter to the variable. In this case, the date
filter is applied to format the date. "Y-m-d"
specifies the desired date format where:
- Y
: Represents the year in four digits (e.g., 2023).
- m
: Represents the month in two digits (e.g., 01 for January, 12 for December).
- d
: Represents the day in two digits (e.g., 01 for the 1st day of the month, 31 for the last day).
```