PDA

View Full Version : QDate Help pls



munna
6th May 2006, 06:39
Hi,

I have a QLineEdit in which the user can enter a date. Since the date field is birthday or anniversary it is highly possible that the user does not remember the year and therfore does not want to enter it.

After validating I want to convert the date into dd MMMM yyyy or dd MMMM format.

There are two problems here.

1. Date Format:

How to distinguish between 10 July 87, July 10 1987, 10 July 1987, 07-10-1987, 07-10-87,10-07-1987, 10-07-87 ..etc ? They are all valid dates. Just that they are entered in different format.

2. Without year:

User might enter 10 Jul, July 10, 10 July etc.. When I validate these dates, QDate will return invalid date and therefore I will not be able to convert it.

Is there a way by which I give user maximum flexibility and still be able to identify the date he entered and convert it to the long month format ?

Thanks a lot.

Kapil
6th May 2006, 07:11
hi..

rather than giving a QLineEdit, why dont you provide the user with the dropdown list type of thing which would not allow the user to enter in any format but to choose from the given options... and then just take on each values and create a string in a format you want to..
try to reduce the inputs from the user to minimum.. this way u can avoid the sort of errors which you listed down...

kapil

munna
6th May 2006, 07:30
I dont want user to select any format. User should be able to enter as normal text (as he usually enteres the date. In different country people enter date in different format) and still be able to see finally the date in dd MMMM yyyy format if he had entered the year otherwise in dd MMMM format.

How can I achieve this?

Thanks a lot.

zlatko
6th May 2006, 08:17
Sorry but why you use QLineEdit instead QDateEdit :eek:

GreyGeek
6th May 2006, 15:58
Hi,

I have a QLineEdit in which the user can enter a date. Since the date field is birthday or anniversary it is highly possible that the user does not remember the year and therfore does not want to enter it.
...
Thanks a lot.

You can subclass a QDate object to use on your data entry form so that any sec tion of the date control can be blank or zeros, and the control will still only accept legal entries for all other possibilities. However, you cannot use a Date type in your database. It must be a varchar2(10) or something similar, accordng to the db you are using and you must convert between the two in your data I/O.

I was given a similar problem. We have a form with a location for the birthdate. It gave space for "__/__/____", but some folks only put in their birth year, and some just the birth month and year. The subclass allowed our clerks to put in zeros or spaces for the month and day sections. But, it made doing SQL selects on the database a pain, so I reverted to the standard QDate control and a date type in the db. The percentage of people born on Jan 1st isn't very great, so we assume that a date of "01/01/yyyy" means that only the year was entered... etc, so only the year is printed on reports and other outputs.

dimitri
7th May 2006, 12:39
I dont want user to select any format. User should be able to enter as normal text (as he usually enteres the date. In different country people enter date in different format) and still be able to see finally the date in dd MMMM yyyy format if he had entered the year otherwise in dd MMMM format.

How can I achieve this?
I think you can't achieve this in the general case. For example, in most of Europe 9/11/2006 means November 9 while in America it would be interpreted as September 11. How do you intend to handle this? You have to force the user into some format or use locale information, maybe together with QComboBoxes as suggested by Kapil.

Kapil
8th May 2006, 06:50
hi...

if you really want to use a QLineEdit sort of thing then i suppose you would have to write check conditions for most of the possible cases... you can also start a simultaneous thread or a check activated whenever the user enters anything in the line edit that he/she is doing it in proper format...
You can use is line Edit isModified() function which on any input given to the line edit enable you to throw some event and this event which would be thrown would be a check specifier or say date processor which would check whether the user is giving in the date in proper format or not...
this way you can force the user to give the input in a set format..
if you want to give the user the privildge to give in any format then it would be very tough for you as you would have to write many conditions and still left with many exceptions which cannot be handled..
so my suggestion would be either a combobox kinda thing or modified text check kind of thing...

Kapil