Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > date/time

Reply
Thread Tools

date/time

 
 
Nader Emami
Guest
Posts: n/a
 
      01-05-2005
L.S.,

Could somebody help me how I can get the next format of date
from the time module?

example: I have to have this time 20050105. It is the next
attributes of format %Y%m%d.

with regards,
Nader
 
Reply With Quote
 
 
 
 
Binu K S
Guest
Posts: n/a
 
      01-05-2005
>>> import time
>>> time.strftime('%Y%m%d',time.localtime())

'20050105'

On Wed, 05 Jan 2005 15:08:37 +0100, Nader Emami <> wrote:
> L.S.,
>
> Could somebody help me how I can get the next format of date
> from the time module?
>
> example: I have to have this time 20050105. It is the next
> attributes of format %Y%m%d.
>
> with regards,
> Nader
> --
> http://mail.python.org/mailman/listinfo/python-list
>

 
Reply With Quote
 
 
 
 
Thomas Guettler
Guest
Posts: n/a
 
      01-05-2005
Am Wed, 05 Jan 2005 15:08:37 +0100 schrieb Nader Emami:

> L.S.,
>
> Could somebody help me how I can get the next format of date
> from the time module?


I don't understand your question. Do you want to have the next day?

20041231 --> 20050101 ?

You can do it like this:
- parse the string with time.strptime
- timetuple[2]+=1
- mktime(timetuple) # --> secs
- strftime(localtime(secs))

HTH,
Thomas

--
Thomas Güttler, http://www.thomas-guettler.de/


 
Reply With Quote
 
Lee Harr
Guest
Posts: n/a
 
      01-05-2005
On 2005-01-05, Nader Emami <> wrote:
> L.S.,
>
> Could somebody help me how I can get the next format of date
> from the time module?
>
> example: I have to have this time 20050105. It is the next
> attributes of format %Y%m%d.
>



I would use the datetime module:


>>> import datetime
>>> today = datetime.date.today()
>>> today

datetime.date(2005, 1, 5)
>>> today.strftime('%Y%m%d')

'20050105'
>>> one_day = datetime.timedelta(1)
>>> tomorrow = today + one_day
>>> tomorrow.strftime('%Y%m%d')

'20050106'


 
Reply With Quote
 
David M. Cooke
Guest
Posts: n/a
 
      01-05-2005
Thomas Guettler <> writes:

> Am Wed, 05 Jan 2005 15:08:37 +0100 schrieb Nader Emami:
>
>> L.S.,
>>
>> Could somebody help me how I can get the next format of date
>> from the time module?

>
> I don't understand your question. Do you want to have the next day?
>
> 20041231 --> 20050101 ?
>
> You can do it like this:
> - parse the string with time.strptime
> - timetuple[2]+=1
> - mktime(timetuple) # --> secs
> - strftime(localtime(secs))


Or using the datetime module:

import time, datetime

tt = time.strptime('20041231', '%Y%m%d')
t = datetime.date.fromtimestamp(time.mktime(tt))
# now in a easier-to-handle form than the time tuple
t += datetime.timedelta(days=1)
print t.strftime('%Y%m%d')


--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments