Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-04-04
8
Medium Priority
?
352 Views
Last Modified: 2010-04-01
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

0
Comment
Question by:royalcyber
  • 4
  • 2
  • 2
8 Comments
 
LVL 11

Expert Comment

by:fargo
ID: 16373091
better is to format in sql query itself. Can you post your query and which db u r using?
0
 
LVL 11

Expert Comment

by:fargo
ID: 16373236
i m not available now..may be someone else can help.
0
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16373326
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16373434
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
 
LVL 23

Accepted Solution

by:
Siva Prasanna Kumar earned 2000 total points
ID: 16373738
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
 

Author Comment

by:royalcyber
ID: 16374635
Thank you very much

It works pretty good
0
 

Author Comment

by:royalcyber
ID: 16376767
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
 
LVL 23

Expert Comment

by:Siva Prasanna Kumar
ID: 16377081
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome to 2018! Exciting things lie ahead in the world of tech. To start things off, we compiled great member articles on how to stay safe, ways to learn, and much more! Read on to start your new year right.
Are you a startup company? Being a startup, you may be using shared hosting, or maybe even dedicated hosting. But have you ever given a thought to using cloud computing now? Yes, don’t be surprised, it is possible for startups to opt for cloud compu…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question