How to get month and year from Date field in sqlalchemy?

前端 未结 2 545
谎友^
谎友^ 2021-01-01 15:54

The result should be Date object

Since the day cannot be \'removed\', set it to say, 1st day of the month.

Leaving only Month, Year

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 16:12

    if you declare your schema like this,

    schema.Column('created', types.TIMESTAMP(), default=now()),
    

    the function now() is defined in the same module which can be like this

    def now():
        now_date = datetime.datetime.now()
        return now_date.replace(day=1)
    

    as per group_by requirement, here is a method mentioned.

    you can modify hour and other field similarly.

提交回复
热议问题