By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,418 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

date/time

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>>> import time
time.strftime('%Y%m%d',time.localtime())
'20050105'

On Wed, 05 Jan 2005 15:08:37 +0100, Nader Emami <em***@knmi.nl> 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

Jul 18 '05 #2

P: n/a
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/
Jul 18 '05 #3

P: n/a
On 2005-01-05, Nader Emami <em***@knmi.nl> 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'
Jul 18 '05 #4

P: n/a
Thomas Guettler <gu*****@thomas-guettler.de> 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
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.