This question has been flagged
4 Replies
11277 Views

Hi,

I need to display current status of timesheet,for that I need current month,can you please help me to find current month from current date??

Thanks in advance.

Avatar
Discard
Best Answer

i assume you have date field in timesheet.

to get moth from that date field use below code

from datetime import datetime


timesheet_date = datetime.strptime(self.timesheet_date, DEFAULT_SERVER_DATE_FORMAT)

month = timesheet_date.month



Avatar
Discard

you can do this in one line timesheet_date = datetime.strptime(self.timesheet_date, DEFAULT_SERVER_DATE_FORMAT).month The return type of month is integer.

Best Answer

  ==If you want to get the number of the current month then try,

date.today().month

If you want to get the  name of the current month then try,

date.today().strftime('%B')
If you want to get the name of the current month in short then try,
date.today().strftime('%b')
For Example, If todays date is 05-01-2019 then
date.today().month           ==> 1
date.today().strftime('%B')  ==> January
date.today().strftime('%b')      ==> Jan
Avatar
Discard

uff si funciona con .year .day
year = date.today().year
mes = date.today().month
dia = date.today().day
gracias!!!

Best Answer
you can filter using domain 
<field name="domain">[('date_field', 'ilike' , context_today().strftime('%m-%Y'))]</field>
Avatar
Discard