This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to Inserting current Date to DataBase 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 "How to Inserting current Date to DataBase" Watch "How to Inserting current Date to DataBase" New topic
Author

How to Inserting current Date to DataBase

prasant sahoo
Greenhorn

Joined: Dec 14, 2007
Posts: 7
In my JSP I am sending the current date as follows

<%java.text.DateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd");
String schduleDate = dateFormat.format(new java.util.Date());
%>

<input type="text" name="scheduledDate" value="<%=dateFormat.format(new java.util.Date()) %>" readonly="true"/>

But in the DataBase (SQL) it is inserting 1/1/1900.
please help
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60748
    
  65

The code you have shown is merely the code that displays the date in an input box. What does it look like on the screen? The way you expect?

Without further details regarding how that date -- remember that when it submitted it will just be a String value -- is being inserted into the database, I'm not sure anyone is going to be able to help you.
[ January 16, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Qussay Najjar
Ranch Hand

Joined: Jan 18, 2008
Posts: 53
What is the database you're using,
If it was Oracle I have a way for you..


Qussay NAJJAR
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
DB2

current date

Oracle

sysdate

mysql

CURDATE()
 
 
subject: How to Inserting current Date to DataBase
 
Similar Threads
Doubt in formatting date
Unparseable Date
problem displaying jsp
weird java dates!!!!
date format problem