473,405 Members | 2,272 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,405 software developers and data experts.

date reformatting


Anyone aware of existing code to turn a date string "8-15-05" into the
number 20050815?

The dateutil module has a parse method that looks perfect, I downloaded
and unzipped it, but could figure out how to install it. I using
windows XP and py2.4.

Any ideas?
Kev

Oct 6 '05 #1
4 1731
setup.py install

Oct 6 '05 #2
There's more than one way, but this one will work for
dates prior to 2000.

import time
datestring='8-15-05'
d=time.strptime(datestring,'%m-%d-%y')
number=10000*d[0]+100*d[1]+d[2]
print number

-Larry Bates

Bell, Kevin wrote:
Anyone aware of existing code to turn a date string "8-15-05" into the
number 20050815?

The dateutil module has a parse method that looks perfect, I downloaded
and unzipped it, but could figure out how to install it. I using
windows XP and py2.4.

Any ideas?
Kev

Oct 6 '05 #3
There's more than one way, but this one will work for
dates prior to 2000.

import time
datestring='8-15-05'
d=time.strptime(datestring,'%m-%d-%y')
number=10000*d[0]+100*d[1]+d[2]
print number

-Larry Bates

Bell, Kevin wrote:
Anyone aware of existing code to turn a date string "8-15-05" into the
number 20050815?

The dateutil module has a parse method that looks perfect, I downloaded
and unzipped it, but could figure out how to install it. I using
windows XP and py2.4.

Any ideas?
Kev


Oct 6 '05 #4
Bell, Kevin wrote:
Anyone aware of existing code to turn a date string "8-15-05" into the
number 20050815?

import datetime
s = "8-15-05"
month,day,year = map(int, s.split('-'))
date = datetime.date(2000+year,month,day)
date.strftime('%Y%m%d') '20050815'

Of course, if you really want the *number* 20050815 you'd
have to do int(date.strftime('%Y%m%d'))


Using a datetime.date object means that you have good
support for a lot of arithmetic on and formatting of
dates without writing a lot of new code.

If you really mean that you want the number 20050815, I
assume this is because some legacy system beyond you control
need to have dates in that format. It's not a particularly
good format for dates. If you just want a numeric storage of
dates, I'd suggest using datetime.date.toordinal/fromordinal.
Those numbers aren't as easy to decipher manually, but at
least they work right if you subtract dates or add or subtract
days from a date.
Oct 11 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
1
by: Bill | last post by:
I currently have a date column that draws from the now() function in my asp script. The date looks like this: 2/5/2004 10:09:52 AM As you can see, there is the day and the time data all in the...
3
by: Les Juby | last post by:
"SELECT id, title FROM Businesses WHERE Date_Added >= " & Request.Form("Since_Date") This SQL string returns all records from the table Businesses and does not seem to be able to recognise...
4
by: yasaswi | last post by:
Now that MySQL 5.0.15 is production ready, are there any functions to use with mysqlimport, so I can load a string such as, MM/dd/yy, in a text file into a MySQL database as a yyyy-MM-dd date...
14
by: Alan | last post by:
Hi everyone! I'm trying to produce a periodic financial report on projects from various departments. My database is set up with the tables tblDepartment, tblProjects, tblPeriods, and tblBudgets...
3
by: Chris Lane | last post by:
Hi, This is super annoying FrontPage like behavior. Does anybody know how I can stop the Visual Studio.NET IDE from reformatting my HTML? Thank You
7
by: Lloyd Sheen | last post by:
I know I have seen a way to stop the terrible reformatting that VS 2003 IDE does. Beyond that is MS going to do a better (could not do a worse) job of auto formatting. Every change I make to...
5
by: neo2020 | last post by:
Hi all, The format of the date given by the javascript date.toLocaleDateString() is not what I want, is it possible to reformat it? Currently, my locale is under US. The...
10
Nathan H
by: Nathan H | last post by:
I have several queries that make a new table for export. I need to find a way to format the date field in the exporting table before I output it. Here is what I am guessing at: Private Sub...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.