Can anyone tell me how to print a date in a desired format in openerp reports. I use both rml and openoffice for reporting
Default Date format in form
Default Date format while printing in reports
My Desired Format
Thanks for your time
Write following code in report py:
import time from datetime import datetime 'get_my_date': self.get_my_date, #Add this line in self.localcontext.update dictionary def get_my_date(self, date): return time.strftime('%d') + '-' + datetime.strptime(date, '%d-%m-%Y').strftime('%b').upper() + '-' + time.strftime('%Y')
Call this method from your rml file:
<para style="P2"> [[ get_my_date(your_date) ]] </para>
If you are adding the fields through the openoffice report editor, try this:
[[ formatLang(o.date_start,date_time=True) ]] (for date + hours) or [[ formatLang(o.date_start,date=True) ]] (date)
Just replace "date_time" with your field. Take heed: this will not show it like your desired format, but it will be better than the default output.
For a better solution, follow Sudhir's instructions.
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 6/12/13, 3:39 AM|
|Seen: 5666 times|
|Last updated: 3/16/16, 12:13 PM|