On Wednesday, March 2, 2016 at 11:23:51 PM UTC-8, [email protected] wrote:
>
> Hi,
>
> db = DAL(..., migrate_enable=False)
>
> db.define_table('table', Field('fld01'), Field('fld02'),'integer',length=7)
>
> db.fld02 actually is a date field with format CYYMMDD.
>

C is either 0 or 9 ?
 

>
> I would like to send this field to view and display as normal date format 
> so that it will work with AJAX calendar. 
>
> How could I do that? Many thanks.
>

Use Python's datetime package, by parsing the integer and using the pieces. 
 The following should work, but is untested:

import datetime


day = fld02 % 100
month = (fld02 / 100) % 100
year    = (fld02/10000) % 100
century = 2000 if (fld02/100000 == 0) else 1900


df = datetime.datetime(century + year, month, day)



This leaves the  hour, minute, seconds parts of df as 0.

You could also do the same thing with datetime.date() depending on your 
form fields.

Using datetime.strptime() isn't going to be any easier, since you would 
have to do the above calculations to turn your integer into string pieces 
to parse.

/dps

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to