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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Convert String to Date

String txtDateOfBirth = request.getParameter("txtDateOfBirth");

I need to change string into date so as I can place in a bean value which has datatype of date
private Date dateOfBirth;




0
calis
Asked:
calis
1 Solution
 
Genetic_WolfCommented:
To avoid any mistake from the computer about the month and day, use

use the Date serail Function

MyString$ = DateSerial(year, month, day)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdateserial.asp

0
 
Genetic_WolfCommented:
Grrr I answer to 10 quesiton today and none of them have been add to my Profiles...

Anyway, I made a mistake when I answer to you, I should have said:

First, Extract Year, Month and Day from your String.
then,

use the dateserial function

dim MyDate as date

MyDate = DateSerial(year, month, day)

This will avoid the computer to mistake Day for Month from any other possible type of conversion.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdateserial.asp

0
 
calisAuthor Commented:
Sorry I am probably in wrong section I am programing Java
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
InternCommented:
calis:
>>Sorry I am probably in wrong section I am programing Java

You should go to Community Support and post a question there asking them to delete this question and refund your points.  Then you can repost this question in the JAVA area.
0
 
jaisuriCommented:
There are different ways of doing this.
1. Use the java.util.Calendar class. COnsidering that you know the format of the data and can parse it, you can use

  Calendar cal = Calendar.getInstance();

  cal.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));

   Date dt = cal.getTime();

2. Use java.text.DateFormat or java.text.SimpleDateFormat which is a subclass of DateFormat.

  You can use DateFormat.parse(String date) to get a java.util.Date object.




0
 
CleanupPingCommented:
calis:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now