Prashanth K
Prashanth K

Reputation: 27

How to compare two date fields with today's date and time

I have to write domain for checking that the present date and time is between two Datetime fields. I wrote the domain, but it shows this error:

DataError: invalid input syntax for type timestamp: "date_from"
LINE 1: ...OM "hr_holidays" WHERE (("hr_holidays"."today" >= 'date_from...
                                             ^

My domain is:

<field name="domain">[('today','&gt;=','date_from'),('today','&lt;=','date_to')]</field>
today = fields.Datetime(default=fields.Datetime.now)`

Please help me.

Upvotes: 0

Views: 210

Answers (1)

dccdany
dccdany

Reputation: 836

just remove the field of today, is pointless, and, in the xml:

<field name="domain">[('date_from', '&gt;', ((context_today()+relativedelta(days=-1)).strftime('%Y-%m-%d'))), ('date_to', '&lt;', ((context_today()+relativedelta(days=1)).strftime('%Y-%m-%d')))]"</field>

I added the relativedelta too so you can play with dates if you need.

Upvotes: 1

Related Questions