problem formatting dates from text fields.

  • Thread starter krishnakant Mane
  • Start date
K

krishnakant Mane

hello all.
thanks for the help and for pointing me to the proper url for wxpython
related issues.
I am so happy that I now have a very easy gui library that can do
practically every thing with such ease (no flames intended but I was
never at so much ease with java swing ).
I however have a problem with dates.
I am tired searching for some good tutorial that can explain the basic
functionality of wx.datetime class and the datetime picker.
I want to display the date in dd/mm/yyyy format and allow the user to
change the dates.
I then will like to take the value (the entire date) and put into a database.
now this is my first question.
the other problem is even more tough to solve with my given knowledge
of wx.datetime and related classes.
unfortunately the database given to me has a text field for date and
the data is neetly entered.
but when I get the data back from that text field I some how want to
convert it back to actual date in the same dd/mm/yyyy format and send
this as a value to my date time picker.
how can I achieve this?
thanking all.
Krishnakant.
 
D

Dennis Lee Bieber

I am tired searching for some good tutorial that can explain the basic
functionality of wx.datetime class and the datetime picker.
I want to display the date in dd/mm/yyyy format and allow the user to
change the dates.

Simplest is probably to do what many web-sites use for credit card
expiration dates... Ignore any pre-built date-time modules...

Create three integer fields, make the first two drop-down lists
pre-populated with days and months. And validate the results later (just
to cover someone putting in 31 02 xxxx).
I then will like to take the value (the entire date) and put into a database.
now this is my first question.

Uhm... WHAT is your first question? There is only one question in
this entire post, and it is near the bottom -- the simple "how can I
achieve this?" (Which, in a way, is as open-ended as stating: "I have
$10, I want to turn it into $1000000 without leaving my bed. How can I
achieve this?")
the other problem is even more tough to solve with my given knowledge
of wx.datetime and related classes.
unfortunately the database given to me has a text field for date and
the data is neetly entered.
but when I get the data back from that text field I some how want to
convert it back to actual date in the same dd/mm/yyyy format and send

You don't show us what format is used in the database, so there is
nothing to base a conversion on. Is it year/month/day, month/day/year;
months numeric or alpha (abbreviated or spelled out). Fields separated
by space, comma, -, :, or /
this as a value to my date time picker.

Note that, based upon the documentation, wxDatePickerCtrl works
internally in wxDateTime -- which is a 64bit integer in milliseconds
(and is NOT compatible with common c/unix time stamps). Any human
readable date time is a formatting operation.

Of course, if you follow my suggestion of simply using three input
fields, the internal format could be anything you need.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
J

John Machin

Dennis said:
Simplest is probably to do what many web-sites use for credit card
expiration dates... Ignore any pre-built date-time modules...

Create three integer fields, make the first two drop-down lists
pre-populated with days and months. And validate the results later (just
to cover someone putting in 31 02 xxxx).

My 2 cents worth:

(1) this annoys the bejaysus out of data inputters who can type
"31\t12" a lot faster than they can pick it out of two drop-down lists.

(2) this would annoy the bejaysus out of data users if they were aware
of the extent of off-by-one errors caused by using drop-down lists.

Cheers,
John
 
K

krishnakant Mane

You don't show us what format is used in the database, so there is
nothing to base a conversion on. Is it year/month/day, month/day/year;
months numeric or alpha (abbreviated or spelled out). Fields separated
by space, comma, -, :, or /

the format in the text field is dd/mm/yyyy which is perfect for what I need.
but the problem as I said is to get this text into a value that can
fit into a date time picker.
can this be done?
Krishnakant.
 
D

Dennis Lee Bieber

the format in the text field is dd/mm/yyyy which is perfect for what I need.
but the problem as I said is to get this text into a value that can
fit into a date time picker.

Assuming you mean the wx picker, I'd think...
from wxPython import wx
aDate = "3/12/2006"
(d, m, y) = [int(x) for x in aDate.split("/")]
wxd = wx.wxDateTimeFromDMY(d, m, y)
wxd
<wx.DateTime: "12/03/06 00:00:00" at _184a4401_p_wxDateTime>

would suffice.

NOTE: I've never used wxPython (though I have installed it and have the
"in Action" book). I found this by just doing various levels of
"dir(wxPython)" (my first import was just for wxPython -- no from .
import . ), "dir(wxPython.wx)", etc. until I found a likely method name.
u'03/12/2006'

Of course, it may be faster to go directly from the string format
rather than hand splitting and converting to integers

These were not difficult to find; most are utility repackaging of
the functions that would be used in a C-program (in fact, one has to
look at the documentation of the C strftime(), or the Python equivalent,
to find out the valid format codes).
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
K

krishnakant Mane

is there a soft copy of wxpython in action available for free download?
I saw the book on my book store but since I am totally blind, I have
to depend on soft copies.
Krishnakant.
 
R

Robert Kern

krishnakant said:
is there a soft copy of wxpython in action available for free download?
I saw the book on my book store but since I am totally blind, I have
to depend on soft copies.

It is not available for free, no. However, it is available in PDF form from
Manning's website:

http://www.manning.com/rappin/

If their Yahoo store is not accessible via your web reader (I have no
experience, so I won't depend on it), you can email the publisher's customer
service at (e-mail address removed) and I'm sure they will get the book to you in a
form you can read.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
H

Hendrik van Rooyen

John Machin said:
Dennis Lee Bieber wrote: 8<--------------------------------------------------

My 2 cents worth:

(1) this annoys the bejaysus out of data inputters who can type
"31\t12" a lot faster than they can pick it out of two drop-down lists.

(2) this would annoy the bejaysus out of data users if they were aware
of the extent of off-by-one errors caused by using drop-down lists.

Cheers,
John

This annoyance can be maximised if, after the selection, a pop up dialog window
is displayed showing what was chosen, along with the following text:

"This is what you have chosen - Please indicate whether or not you wish to re
try"

- with the focus on the "yes" button.
and then, when "yes" is chosen, to start again without any attempt to remember
the previously entered values

- Hendrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top