how to format a date to be displayed like mm/dd/yyyy

I have this text field where I am displaying value from a sql database

<td><input type="text" class="textfield" size="30" name= "EVENT_DATE" value=("<%= checkNull((String)selected_event.getEvent_date())%>"),       maxlength="80" readonly onClick="cal.select(document.forms['myform'].EVENT_DATE,'anchor','MM/dd/yyyy'); return false;">

The data is stored as date/time format in the database and shows something like this in the text field
1900-01-01 00:00:00.0

but I need it to displayed like this

01/01/1900

Any help will be greatly appreciated

royalcyberAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fargoCommented:
better is to format in sql query itself. Can you post your query and which db u r using?
0
fargoCommented:
i m not available now..may be someone else can help.
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
check out the link.

http://javaalmanac.com/egs/java.text/FormatDate.html

i think its done as it was previous a accepted answer for me.
:-)
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Format formatter;
formatter = new SimpleDateFormat("MM/dd/yy");
String s = formatter.format(date);

use the above java code in JSP before assinging it to text box do this formatting & then assign.
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
and one more thing is the below code expects you to give a date object

String s = formatter.format(date);

so while getting the date from data base result set use getDate() function of the result set and assign to date and then format the date and then assign to the text box.

Thank you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
royalcyberAuthor Commented:
Thank you very much

It works pretty good
0
royalcyberAuthor Commented:
I am sorry

when i restarted the browser i gives the following  error

org.apache.jasper.JasperException: Cannot format given Object as a Date


Would you know any way I can parse directly in JSP

Thanks

0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
just put a try & catch block across the above code & check i think you may be getting a SQL Exception.
did you just use simple getDate() function or

 Date getDate(int columnIndex) ;
     
 Date getDate(int columnIndex, Calendar cal) ;

 Date getDate(String columnName) ;

 Date getDate(String columnName, Calendar cal) ;

which function have you tryed using???
     
and more on i don't think its a Date object which has been stored in your database it seems to be a timeStamp Object so try doing this and let me know if there is some problem

Date date = rs. getTimestamp(int columnIndex);

just replace the getDate() with the above statement.

Thank you
                       
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.