Add one year in current date PYTHON

后端 未结 8 1501
别跟我提以往
别跟我提以往 2020-11-29 01:59

I have fetched a date from database with the following variable

{{ i.operation_date }}

8条回答
  •  无人及你
    2020-11-29 02:23

    It seems from your question that you would like to simply increment the year of your given date rather than worry about leap year implications. You can use the date class to do this by accessing its member year.

    from datetime import date
    startDate = date(2012, 12, 21)
    
    # reconstruct date fully
    endDate = date(startDate.year + 1, startDate.month, startDate.day)
    # replace year only
    endDate = startDate.replace(startDate.year + 1)
    

    If you're having problems creating one given your format, let us know.

提交回复
热议问题