Click here to Skip to main content
15,920,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi
i want that user can enter different types of date format in the feild and i can validate the format and save it into database..

$dateFormat = "d-m-Y";

i want the user can enter date n this way also
DD-MM-YYYY
DD/MM/YYYY
DDMMYYYY

if any of one is validate is save it in to database
plz help
Posted

Ummm, that's not a good design approach. The data should be normalized to a single format before storing it in the database. After they enter the date, it should be validated, and converted to the "proper" format, whatever that proper format is.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 20-Jan-11 12:37pm    
I don't think there is a contradiction; the question did not assume the approach different from yours; they probably need just the code. But the question indicates OP's laziness.
Manfred Rudolf Bihy 20-Jan-11 12:44pm    
Well spotted, that were my thoughts also eventhough going by what I usally encounter here I'd say John probably is right in his assumptions. :)
Manfred Rudolf Bihy 20-Jan-11 12:45pm    
Good advice! 5+
#realJSOP 20-Jan-11 12:57pm    
From OP: thx i will use only one format, and again thx
You really can't allow users to decide how to enter data. Next thing you know they'll want to actually use the stuff. :)

Seriously though, add a Label above (or below) the entry box stating the acceptable format. e.g. 'Date as DD-MM-YYYY' or whatever the 'standard' is where you are. It need not be the same as the format of your database since you can take care of any conversion behind the scenes.
 
Share this answer
 
Comments
#realJSOP 20-Jan-11 12:59pm    
I think it's just as easy to try to parse the entered data with a reasonable number of formats before giving up and telling the user he's an idiot. At the same time, you're correct - a user must be told how the data should be entered. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900