cancel
Showing results for 
Search instead for 
Did you mean: 

What is the difference between java.sql.date and java.util.date

Former Member
0 Kudos

Hi All,

What is the difference between java.sql.date and java.util.date and which is more preferable to use .How to convert date from one form to another .

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

former_member186016
Active Contributor
0 Kudos

Go through these post:

http://lists.mysql.com/mysql/202513

How to convert:

Go through this link also: Good one to understand dates from Java

http://www.onjava.com/pub/a/onjava/2003/06/05/java_calendar.html

Regards,

Ashwani Kr Sharma

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi

See this link... U can get different ideas in those conversations..

http://www.geekinterview.com/question_details/25307

Urs GS

Former Member
0 Kudos

Hi

And also see This how to change date from one form to other..

How to change a date value from "java.util.Date" to

> "java.sql.Date"?

<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html">java.util.Date</a> date = // date

<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Date.html">java.sql.Date</a> sqlDate = new <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Date.html#Date(long)">java.sql.Date(</a> date.<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html#getTime()">getTime()</a> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Date.html#Date(long)">)</a>

Urs GS

Former Member
0 Kudos

Hi kl..

java.util.date is the java representation of date and time. Use this if you want to deal with dates or times in your java program (add, substract etc).

java.sql.date is for use only if you want to communicate with a SQL-Database like MySQL, MSSQL, PostGreSQL or so. Don't use it for the above mentioned stuff.

If you were using it for SQL-stuff, I guess you'd know that, so perhaps java.util.date is the right one for you.

I believe java.util.Date includes time (HH:MM:SS); java.sql.Date does not.

java.sql.Timestamp allows you to hold onto database timestamps down to the millisecond. - MOD

Urs GS

Former Member
0 Kudos

HI ,

util date is a superclass of sql date.

util date will be in yyyy-mm-dd format while sql date is in yyyy/mm/dd format by default.

If u create a date type context variable in Webdynpro, it will be sql date by default. sql date is commonly used for date values in back end. If u import a date variable from an RFC, it will be of sql date..

Regards

Fahad Hamsa

Former Member
0 Kudos

Hello Kl,

If you think from <b>WebDynPro and R/3</b> point of view Date is only <b>java.sql.Date.</b>

Depends upon Scenario we have to use

<u><b>Differences</b></u>

java.util.date is the java representation of date and time. Use this if you want to deal with dates or times in your java program (add, substract etc).

java.sql.date is for use only if you want to communicate with a SQL-Database like MySQL, MSSQL, PostGreSQL or so. Don't use it for the above mentioned stuff.

If you were using it for SQL-stuff, I guess you'd know that, so perhaps java.util.date is the right one for you.

believe java.util.Date includes time (HH:MM:SS); java.sql.Date does not.

java.sql.Timestamp allows you to hold onto database timestamps down to the millisecond. - MOD

Rgds

-SS

former_member751941
Active Contributor
0 Kudos

Hi Ki,

Check this thread.

To convert the date in to other format you have to use SimpleDateFormat.

Package

-


import java.sql.Date;

import java.text.ParseException;

import java.text.SimpleDateFormat;

Code:-

-


SimpleDateFormat smpdtFormat =new SimpleDateFormat("yyyy-MM-dd");

String vFr="";

vFr = wdContext.nodeProductDate().getElementAt(0).getAttributeValue("Validfr").toString();

prodElem.setValidFrom(new Date(smpdtFormat.parse(vFr).getTime()));

Check this threads...

Regards,

Mithu