If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Best way to inpu Dates from Java application in MySQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-11-05, 12:30
B_taki B_taki is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Best way to inpu Dates from Java application in MySQL

Hi,

I'm pretty new to mysql, and a little expirienced in Java and i've come to a problem. I need to put a date that a user inputs in a form in the app in a table field of the type DATE in mysql. I dont need the time, only the Date. The Date format in my area is dd/MM/yyyy. I'm trying something with a JFormattedTextField, although that's new to me too.

So, i want to know the best way to make that text field (formatted or not) to accept only values in the format mentioned above, and to input that(after Ok is clicked) in a mysql table field without too many lines of code if its possible. I hope this is an easy question for an expirienced programmer. Thanks.
Reply With Quote
  #2 (permalink)  
Old 01-11-05, 13:53
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
have the date put in as yyyymmdd then use date_format to display your results.
Reply With Quote
  #3 (permalink)  
Old 01-11-05, 17:01
B_taki B_taki is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
I don't think I understand what are you saying exactly. I want the users to input the date in the dd/MM/yyyy format. I'm thinking now is there a way to remember that value as some date object and then change the format to what mysql can recognize. Actually is there a way to input values in mysql using some date object or do i have to parse the date value as a String and enter it "manually". And how do i make the text field initialize to the current date, because it's highly unlikely that it will require changes.
Reply With Quote
  #4 (permalink)  
Old 01-11-05, 20:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
when you provide a date value for mysql, you have several choices for the format of that date value:

- a string 'YYYY-MM-DD '
- a string 'YY-MM-DD'
- a string 'YYYYMMDD'
- a string 'YYMMDD'
- a number YYYYMMDD
- a number YYMMDD

you cannot insert any other format into a DATE field

so, to answer your question, you must either

1) re-assemble the user's input into one of the above formats before you prepare the value to be inserted

2) insert the user's mm/dd/yyy value into a CHAR or VARCHAR field, and then use SUBSTRING and CONCAT functions in an sql UPDATE statement to set the DATE field to the correct re-assembled value
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-12-05, 09:24
B_taki B_taki is offline
Registered User
 
Join Date: Dec 2004
Posts: 3
Ok, I get the idea. Thanks a lot!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On