finding first day of the month in python

后端 未结 11 893
挽巷
挽巷 2021-02-02 05:39

I\'m trying to find the first day of the month in python with one condition: if my current date passed the 25th of the month, then the first date variable will hold the first da

11条回答
  •  情歌与酒
    2021-02-02 05:44

    First day of next month:

    from datetime import datetime

    class SomeClassName(models.Model):
        if datetime.now().month == 12:
            new_start_month = 1
        else:
            new_start_month = datetime.now().month + 1
    

    Then we replace the month and the day

        start_date = models.DateField(default=datetime.today().replace(month=new_start_month, day=1, hour=0, minute=0, second=0, microsecond=0))
    

提交回复
热议问题