473,320 Members | 1,946 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,320 software developers and data experts.

Conversion of String to Date Type

Hello All,

I've joined the wxPython list, but this is my first post on the python
list and it's good to be here :^) Anyway...

My question is relating to Date equality. I am checking if two string
representations of dates are less than or equal to eachother. The issue
that I am having is that the date strings, ex.
09/15/04 is evaluated as > 09/14/04. However, when the last two digits
for the year are changed, like this 09/15/04 is considered > 09/15/05.
I thought this had something to do with evaluating two strings. Could
this be the case, if so does someone know of a way to convert those
strings into a Date type object?

I look forward to hearing all of your feedback, thanks in advance.

Keith Bolton
Jul 18 '05 #1
2 5102
Keith Bolton wrote:
Hello All,

I've joined the wxPython list, but this is my first post on the python
list and it's good to be here :^) Anyway...

My question is relating to Date equality. I am checking if two string
representations of dates are less than or equal to eachother. The issue
that I am having is that the date strings, ex.
09/15/04 is evaluated as > 09/14/04. However, when the last two digits
for the year are changed, like this 09/15/04 is considered > 09/15/05.
I thought this had something to do with evaluating two strings. Could
this be the case, if so does someone know of a way to convert those
strings into a Date type object?

String comparision doesn't know anything about the special semantics of
dates, and e.g. "09/15/04" is lexically before "10/15/03".
Possible solutions:
- use something like YYYYMMDD, YY/MM/DD... as string representation,
these will be sorted correctly (which is a good habit anyway, e.g. if
you have a bunch of files with a date in the filename)
- try "ts = time.mktime(int(s[6:8])+2000, int(s[3:5]), int(s[0:2]))" to
create timestamps and compare these. The datetime modules may have more
useful functions (haven't used it yet, time was sufficient for me).
- where do these strings come from? Perhaps there is an underlying
timestamp or datetime object that you could use instead of "string
representations".
Jul 18 '05 #2
On Fri, 17 Sep 2004 11:19:12 -0700, Keith Bolton wrote:
Hello All,

I've joined the wxPython list, but this is my first post on the python
list and it's good to be here :^) Anyway...

My question is relating to Date equality. I am checking if two string
representations of dates are less than or equal to eachother. The issue
that I am having is that the date strings, ex. 09/15/04 is evaluated as
09/14/04. However, when the last two digits for the year are changed,

like this 09/15/04 is considered > 09/15/05. I thought this had
something to do with evaluating two strings. Could this be the case, if
so does someone know of a way to convert those strings into a Date type
object?


Check out dateutil's fuzzy parser. It's great for handling this sort of
thing.

https://moin.conectiva.com.br/DateUt...81611e5ae207a5

HTH
Anna
Jul 18 '05 #3

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

Similar topics

3
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
1
by: heirou | last post by:
I'm a novice in this subject....I've made a database that requires a time conversion. For example, if local time is 1200, determine the time in Korea. I use two fields: a date field, and a time...
4
by: Ching-Lung | last post by:
Hi, I have web browser control in my windows form and am implementing the following event: ***************************************** public void BeforeNavigate(string URL, int Flags, string...
7
by: Alphonse Giambrone | last post by:
How can I convert a string to a different type based on another string or other variable? For instance, instead of Dim i as Integer i = ctype("1000", Integer) I would like to do
1
by: itfgnanvigneshwari | last post by:
hai, as i am new to php field i had a problem in date field. i have table named student with fields fieldname type name varchar...
4
by: Phillip Vong | last post by:
VS2005 in VB.NET I have 2 simple textboxes (Textbox1, Textbox2) and they both have dates. Textbox1=12/31/2006 Textbox2=12/15/2006 I need to convert these two textboxes that are in String...
10
by: =?Utf-8?B?TWlrZQ==?= | last post by:
I have a string variable containing a date formatted as YYYYMMDD For example - Dim x as string = "20070314" If I try to perform a type conversion as follows I get an error: Dim y as Date =...
0
by: =?Utf-8?B?RGVuaXMgU29oZXQ=?= | last post by:
Hi all, I've created a new project to test ObjectDataSource component. I've just added a new objectdatasource, configured it (linked to a table) etc ... It works fine on localhost, i can...
7
by: bruce.dodds | last post by:
Access seems to be handling a date string conversion inconsistently in an append query. The query converts a YYYYMM string into a date, using the following function: CDate(Right(,2) & "/1/" &...
2
by: RN1 | last post by:
A TextBox displays the current date (in dd/mm/yyyy format) & time when a user comes to a page (e.g. 15/10/2008 1:36:39 PM). To convert the date into international format so that the remote server...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.