Mysql gets a month from timestamp not working

I have a query that pulls the correct db data form but does not return me a month from the timestamp. In the timestamp column, I get a null value, although the timestamp is exsists. These are stores in the database like bigInt (this is not my idea).

I need a date returned as follows:

Course | fcpd | Month 216 0.5 04 

but I get:

 Course | fcpd | Month 216 0.5 null SELECT mdl_quiz.course, mdl_quiz.fcpd, MONTH(mdl_quiz_grades.timemodified) as Month FROM mdl_quiz INNER JOIN mdl_quiz_grades ON mdl_quiz.course = mdl_quiz_grades.quiz WHERE mdl_quiz_grades.userid = 9428 AND mdl_quiz.course = 215 

Can someone please indicate where I am going wrong?

+4
source share
2 answers

First you need to convert the timestamp to a date before you can apply the MONTH() function.

 MONTH(mdl_quiz_grades.timemodified) 

becomes

 MONTH(FROM_UNIXTIME(mdl_quiz_grades.timemodified)) 

More on this.

And as an alert, int enough to timestamp, bigint not required. A timestamp is a 32-bit number, so it can hold the maximum date on January 19, 2038.

+9
source
 "SELECT count(*) as records FROM sms WHERE MONTH(tarih)=MONTH(NOW()) and ceptel='"&ceptel&"'" 
0
source

All Articles