Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > problem formatting dates from text fields.

Reply
Thread Tools

problem formatting dates from text fields.

 
 
krishnakant Mane
Guest
Posts: n/a
 
      12-03-2006
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.
 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      12-03-2006
On Mon, 4 Dec 2006 01:11:30 +0530, "krishnakant Mane"
<> declaimed the following in comp.lang.python:

> 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

HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-)
HTTP://www.bestiaria.com/
 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      12-03-2006

Dennis Lee Bieber wrote:
> On Mon, 4 Dec 2006 01:11:30 +0530, "krishnakant Mane"
> <> declaimed the following in comp.lang.python:
>
> > 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).
>


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

 
Reply With Quote
 
krishnakant Mane
Guest
Posts: n/a
 
      12-04-2006
On 04/12/06, Dennis Lee Bieber <> wrote:
> 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.
 
Reply With Quote
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      12-04-2006
On Mon, 4 Dec 2006 07:14:22 +0530, "krishnakant Mane"
<> declaimed the following in comp.lang.python:

>
> 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.

>>> wxd.FormatDate()

u'12/03/06'
>>> wxd.FormatISODate()

u'2006-12-03'
>>>
>>> wxd.Format("%d/%m/%Y")

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

>>> wxdd = wx.wxDateTime() #uninitialized datetime
>>> bDate="25/12/2006"
>>> wxdd.ParseFormat(bDate, "%d/%m/%Y") #set it to a value

10
>>> wxdd

<wx.DateTime: "12/25/06 00:00:00" at _687fab00_p_wxDateTime>
>>>


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

HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: web-)
HTTP://www.bestiaria.com/
 
Reply With Quote
 
krishnakant Mane
Guest
Posts: n/a
 
      12-04-2006
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.
 
Reply With Quote
 
Robert Kern
Guest
Posts: n/a
 
      12-04-2006
krishnakant Mane wrote:
> 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 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

 
Reply With Quote
 
Hendrik van Rooyen
Guest
Posts: n/a
 
      12-04-2006
"John Machin" <> wrote:
> Dennis Lee Bieber wrote:

8<--------------------------------------------------
> > 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


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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RFC-822 dates into Ruby dates kellygreer1 Ruby 1 06-08-2008 10:59 PM
Need to use dates earlier than 1900 (Time library says out of range for dates < 1900) me@benjaminarai.com Ruby 1 07-17-2007 02:25 PM
FAQ Dates; Opera Dates. Dr J R Stockton Javascript 0 06-18-2007 03:51 PM
Dates dates dates dates... SQL and ASP.NET David Lozzi ASP .Net 1 09-30-2005 02:18 PM
Dates! Dates! Dates! PW ASP General 4 08-09-2004 04:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57