How to concatenate year and month in table 8.0.0?

I have a datetime field. 2013-08-22 12:00:00 AM. I want to combine the year and month, and I want the result to be 201308.

When I try year (datetime_field) + month (datetime_field), what I get is 2013 + 08 = 2021 .. that is, it adds instead of contacting. Can anyone tell how to get output like 201308?

+4
source share
1 answer

something more like

str(year(datetime_field)) + str(month(datetime_field)) 

should give you what you want.

The str function converts your numeric data into a string, setting + as the string concatenation operation instead of the arithmetic add operation.

+12
source

Source: https://habr.com/ru/post/1498383/


All Articles