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 JDBC and Relational Databases and the fly likes Default date 1970-01-01 being displayed in SQL 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 » Databases » JDBC and Relational Databases
Bookmark "Default date 1970-01-01 being displayed in SQL" Watch "Default date 1970-01-01 being displayed in SQL" New topic

Default date 1970-01-01 being displayed in SQL

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1076

I harcoded a variable creation data in a java file which in turn inserts into the table but the issue here is its inserting date with the date value:1970-01-01

Date creationdate=new Date(2013-02-10);

Please advice where I am going wrong. || OCJP:81%
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

If that's really your line of code, it's not doing what you want it to. First you subtract 2 (octal) and 10 from 2013, leaving 2011. You then create a new Date object that is 2011 milliseconds (or just over 2 seconds) past midnight on January 1st 1970.

You should check out DateFormat and SimpleDateFormat if you want to convert any String into a Date, and Calendar or GregorianCalendar if you want to create a Date object for a specific date/time.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Default date 1970-01-01 being displayed in SQL
It's not a secret anymore!