Showing posts with label Mysql MONTH(). Show all posts
Showing posts with label Mysql MONTH(). Show all posts

Tuesday, 28 August 2018

MySQL MOTH () does not return the correct value

I'm trying to execute a query that gets the month from a date and it seems to give me an incorrect moth;

Code is:
MONTH(FROM_UNIXTIME(Datum))

And Datum is:
24/01/2017

The result should be 01 or 1 but instead it is 12 and I don't know why... If I don't try to get the moth of that date, it will give me 24/01/2017 so I'm not sure what's wrong...
Can anyone help me?

If your Datum is 24/01/2017, try following:
month(str_to_date('24/01/2017', '%d/%m/%Y'))