This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Wrongly Date is updated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wrongly Date is updated" Watch "Wrongly Date is updated" New topic

Wrongly Date is updated


Joined: Mar 27, 2009
Posts: 1

I tried to insert the date in the format dd/MM/yyyy into the mysql where the format is yyyy-MM-dd. Please see the screnario below

The issue was, the entered month is taken as date and entered date is taken as month.

So if the date entered is 13, then month is become 1 (13 - 12) and remaining 12 month is added in the year.

For example, when the date 03/13/2008 is entered , it is saved in data base as 2009-01-03.

For example, when the date 03/27/2008 is entered , it is saved in data base as 2010-03-03.

(27 = 2 years 3 months. so 2008 become 2010 and 27 - 24 become as 03 )

But before this issue is fixed, there were around 5000 records inserted in the DB. Now we can not ask the customer to reenter the dates. Is there any possibility to find the correct date from this wrong date?

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15101

RH KA, please check your private messages for an administrative matter. You can see them by clicking My Private Messages.

No, there is no way you can repair that, because information on the correct date has been lost because of the error.

For example, if the date in the database is 2009-01-03, how do you know if the user entered 1 March 2009 or 13 March 2009 or something else? There's no way to distinguish between the different possibilities, so it is impossible to repair this.

I'm afraid there is nothing you can do other than ask the customer to reenter the dates.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
K. Tsang

Joined: Sep 13, 2007
Posts: 3135

Are you working with JDBC or SQL? You can try using the java.text.SimpleDateFormat to ensure the format is yyyy-mm-dd or whatever you like before updating the field.

K. Tsang JavaRanch SCJP5 SCJD OCPJP7 OCPWCD5 OCPBCD5 OCPWSD5 OCMJEA5 part 1 part 2/3
I agree. Here's the link:
subject: Wrongly Date is updated
jQuery in Action, 3rd edition