Hi!

Date now = new Date( System.currentTimeMillis() );
SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy hh:mm:ss" );

String snow=sdf.format( now );
out.println( snow );

prints

07/02/2008 03:22:32

but when I'm trying to send a query involving 'now' string that contains the datetime, I get this on the sql database

2008-02-07 00:00:00

. Im only getting the date whereas I should be getting date and time... how to fix it?

Use the TimeStamp class to get and set the field in the DB, not the Date class. In SQL a Date, is a Date, and does not contain a Time. You can then transfer that value to a Date object later, if you wish.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.