콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
21845 화면

Dear Friends,

How to split month and year from date field and fetch that result in char field.Please advice me guys to done this.

아바타
취소
베스트 답변

Can you also use this code in the GUI?

아바타
취소
베스트 답변

Try this friend:


import time

import datetime

from datetime import date

from datetime import datetime, date, time

ref_id = False

y = False

m = False

state = False

d = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

print d

d_ref = datetime.strptime("2011-01-11","%Y-%m-%d")

print d_ref

d_to = datetime.strptime("2012-01-31","%Y-%m-%d")

print d_to

if d_ref < d_to :

d_ref = d_to

y = d_to.year

m = d_to.month

day = d_to.day

print y

print m

print day

print d

print (str(y),str(m),str(01))

You can eliminate the day :)

Regards.

아바타
취소
베스트 답변

Hi,,

Try this script:-

date = datetime.strptime(date_field, DEFAULT_SERVER_DATE_FORMAT)
month = date.month
year = date.year

Hope this helps..

아바타
취소
베스트 답변

Hi Vadivel,

From Date field you will get date as string,  first convert it to datetime object type using:
date = datetime.strptime([your string date], "%Y-%m-%d") 

then you can simply use datetime attributes to get month and year as:

" print date.month, print date.year......." 

To show it in another field you can use on_change() method of [your date] field.

Don't forgot to import datetime at top as;

"from datetime import datetime"

Hope it helps you !    

아바타
취소
관련 게시물 답글 화면 활동
0
3월 15
3593
0
7월 15
3046
1
3월 15
4931
3
6월 25
1276
1
1월 25
18073