0
I have a model that is basically the following :
class Sample(models.Model):
date = fields.DateField(auto_now=True)
Now, with this I want to filter only the month in this model
How I only get the month on this model ?
0
I have a model that is basically the following :
class Sample(models.Model):
date = fields.DateField(auto_now=True)
Now, with this I want to filter only the month in this model
How I only get the month on this model ?
0
You can use the module datetime to do this.
Use the method .strftime(). See below:
from datetime import datetime
data_hora = datetime.now()
mes = data_hora.strftime('%m')
print(mes)
It will return only the month of the current time.
This way you transform your object datetime for an object str. It does this according to the formatting passed as argument to the method .strftime(). To get deeper into the formatting I recommend this reading.
Browser other questions tagged python django flask
You are not signed in. Login or sign up in order to post.