please check dateutils.

It works will almost all date-time formats, it intelligently convert
to datetime object .

labix.org/python-dateutil

On 11/3/11, Omi Chiba <[email protected]> wrote:
> Vineet,
>
> Thanks for sharing.
> It works like a charm !
>
> On Nov 2, 10:27 am, Vineet <[email protected]> wrote:
>> Recently, I wrote this function for my purpose.
>> See if this helps you.
>> Assuming that argument 'dte' input format is -->>  "03-11-2011"
>>
>> [CODE]
>> import datetime, string
>>
>> def str_to_dt(dte):
>>     dte = str(dte)
>>     dte = string.strip(dte)
>>     if len(dte) == 10:
>>         y = int(dte[6:])
>>         m = int(dte[3:5])
>>         d = int(dte[:2])
>>         return datetime.date(y, m, d)
>> [/CODE]
>>
>> This returns output in "python datetime.date" format.
>>
>> --Vineet
>>
>> On Nov 2, 8:19 pm, Omi Chiba <[email protected]> wrote:
>>
>>
>>
>>
>>
>>
>>
>> > This is more like python question but
>>
>> > jj.J2NSD is integer and has value = 20111130 (YYYYMMDD)
>>
>> > I want to set the value as default value of FFNSD which is 'date'
>> > type.
>>
>> > Field('FFNSD', 'date'),
>>
>> > I think I need to import datetime and convert from integer or stiring.
>> > Is anyone know easy way to do it ?
>>
>> > This doesn't work because it set string to date...
>>
>> > db.FEDEXFORM.FFNSD.default = str(jj.J2NSD)[0:4]+"-"+str(jj.J2NSD)
>> > [4:6]+"-"+str(jj.J2NSD)[6:8]

Reply via email to