473,801 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1749
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(2 000+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.strfti me('%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.t oordinal/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
6565
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 Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
1
2292
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 same string. What I would like to do is run a group by clause that groups all the dates that are on the same day togeather. But how do I seperate
3
1371
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 Request.Form("Since_Date") as a valid date. The Since_Date value is entered into a form field as "01-Jan-2005" and appears to be treated as a date; when viewing the SQL statement(with a response.write) it shows the date as 1/1/2005 even if it is...
4
4859
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 value. Thanks, Yasaswi
14
4359
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 -- the first three serve the obvious function; the last table contains foreign keys to tblProjects and tblPeriods, each record corresponding to a project's budget for a particular period. Periods are also grouped by years (a seperate field for...
3
1375
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
1244
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 the format of the page causes reformatting which totally gets rid of the idea that controls are nested and have some structure. Please help
5
7660
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 date.toLocaleDateString() showing Wednesday, July 18, 2007, will it be possible to format it to July 18, 2007 (MM dd, yyyy)? Thanks
10
6969
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 cmdAWBCSINGLE_Click() 'On Error GoTo RUNAPP_ERROR DoCmd.SetWarnings False DoCmd.OpenQuery "qryAWBCTEST" DoCmd.OpenQuery "qryAWBCSINGLE" Table!tblAWBC!.Format = "YYYYMMDD"
0
9697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9555
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10291
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10260
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9100
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7589
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6827
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.