mysql get month from timestamp not working

前端 未结 2 1445
谎友^
谎友^ 2021-01-13 09:05

I have a query that pulls the correct data form a db, but it does not return me the month from the timestamp. In the timestamp column I get a null value, even though the tim

2条回答
  •  逝去的感伤
    2021-01-13 09:31

    You need to convert the timestamp back to a date first, before you can apply the MONTH() function.

    MONTH(mdl_quiz_grades.timemodified)
    

    becomes

    MONTH(FROM_UNIXTIME(mdl_quiz_grades.timemodified))
    

    Read more about it here.

    And as a sidenote, int is enough for a timestamp, bigint is not necessary. A timestamp is a 32bit number, that's why it can hold the maximum date of January 19, 2038.

提交回复
热议问题