File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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: 1055

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: 19649

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
Similar Threads
Date Formatting
Specify Date as 0000-00-00
Customizing java Calendar
Date 01/01/1970 returning non-zero value for time