how to get next month string?

Yinghe Chen yinghe.chen at jeppesen.com
Wed Jul 25 12:16:29 CEST 2007


John's method works perfectly, thanks all for your kind help.
"John Machin" <sjmachin at lexicon.net> wrote in message 
news:1185279342.863711.246700 at d30g2000prg.googlegroups.com...
> On Jul 24, 8:31 pm, "Yinghe Chen" <yinghe.c... at jeppesen.com> wrote:
>> Hi,
>> Could someone help on how to use python to output the next month string 
>> like
>> this?
>>
>> "AUG07", suppose now is July 2007.
>>
>> I think also need to consider Dec 07 case, it is supposed to output as
>> below:
>> "JAN07".
>>
>> datetime module seems not supporting the arithmatic operations, any 
>> hints?
>>
>> Thanks in advance,
>>
>> Yinghe Chen
>
>>>> import datetime
>>>> def nextmo(d):
> ...   mo = d.month
> ...   yr = d.year
> ...   mo += 1
> ...   if mo > 12:
> ...     mo = 1
> ...     yr += 1
> ...   return datetime.date(yr, mo, 1).strftime('%b%y').upper()
> ...
>>>> nextmo(datetime.date(2007,7,15))
> 'AUG07'
>>>> nextmo(datetime.date(2007,12,15))
> 'JAN08'
>>>>
> 





More information about the Python-list mailing list