Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

HOW TO DISPLAY THE YEAR NOW ON A FIELD?

By
louie
on 1/18/15, 10:05 PM 608 views

COULD ANYONE GIVE ME A SAMPLE CODE THAT SHOWS THE YEAR NOW ON A FIELD?

TAKE NOTE: YEAR ONLY. EX. 2014

1

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3918
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 1/19/15, 1:03 AM

from datetime import datetime
year = datetime.strftime(datetime.today(), '%Y')

The following directives can be embedded in the format string:

Directive    Meaning
%a     Weekday name.
%A     Full weekday name.
%b     Abbreviated month name.
%B     Full month name.
%c     Appropriate date and time representation.
%d     Day of the month as a decimal number [01,31].
%H     Hour (24-hour clock) as a decimal number [00,23].
%I     Hour (12-hour clock) as a decimal number [01,12].
%j     Day of the year as a decimal number [001,366].
%m     Month as a decimal number [01,12].
%M     Minute as a decimal number [00,59].
%p     Equivalent of either AM or PM.
%S     Second as a decimal number [00,61].
%U     Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Sunday are considered to be in week 0.
%w     Weekday as a decimal number [0(Sunday),6].
%W     Week number of the year (Monday as the first day of the week) as a decimal number [00,53]. All days in a new year preceding the first Monday are considered to be in week 0.
%x     Appropriate date representation.
%X     Apropriate time representation.
%y     Year without century as a decimal number [00,99].
%Y     Year with century as a decimal number.
%Z     Time zone name (no characters if no time zone exists).
%%     A literal '%' character.

1
louie
On 1/20/15, 12:46 AM

WHAT IS THE CODE FOR THE COLUMNS? 'YEARNOW' = FIELDS.INTEGER? BECAUSE GOING TO USE IT IN A COMPUTATION. YEARNOW-YEAREFFECT = ANS. OF THIS - 30/30 * RCN. MUCH BETTER IF YOU CAN PROVIDE THE CODE ON THAT COMPUTATION.

1
Demirel yakito
On 1/19/15, 1:00 AM

import time

time.strftime("%Y")

1
Anand
On 1/19/15, 12:56 AM

from datetime import datetime
StartDate = "10/10/11"

current_date=datetime.now()

print current_date.year

if u need year current_date.year

if  need day current_date.day

if u need month current_date.month

0
Umashankar Subramani
On 1/20/15, 1:07 AM

col_year= fields.date() just try this field........

Your Answer

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

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/18/15, 10:05 PM
Seen: 608 times
Last updated: 3/28/15, 3:13 AM