تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
21657 أدوات العرض

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
مارس 15
3430
0
يوليو 15
2952
1
مارس 15
4777
3
يونيو 25
961
1
يناير 25
17852