I have a number represented month and i want to replace it with month name, date filter not working:
{{ monthnumber|date:"M" }}
I want to place two links - next month and previous month, but i have only number of month.
How to do it?
Please do as follows: Select a blank cell next to the sales table, type the formula =TEXT(A2*29,"mmm") (Note: A2 is the first number of the Month list you will convert to month name), and then drag the AutoFill Handle down to other cells. Now you will see the numbers (from 1 to 12) are converted to normal month names.
To convert month number to month name we have to use a function MONTHNAME(), this function takes date column or a date as a string and returns the Month name corresponding to the month number.
You'll need a custom template filter to convert the number into a month name. Pretty simple if you use the calendar
module from the standard library:
import calendar
@register.filter
def month_name(month_number):
return calendar.month_name[month_number]
Usage example:
{{ 5|month_name }}
will output May
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With