473,326 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

date/time

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
4 1547
>>> 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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
13
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly things can turn ugly quickly. I would like to use a...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
3
by: colleen1980 | last post by:
Hi: Data in my table is in that format. How to i separate date with time. 11/9/2006 10:10:46 AM Thank You.
6
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
4
by: ahmurad | last post by:
Dear Brothers, I am struggling the following four Date-Time type values which were inputted into MYSQL database in different tables. As MYSQL Default Time Format: YYYY-MM-DD HH:MM:SS, So I used...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.