The Artima Developer Community
Sponsored Link

Java Answers Forum
JDBC Current Date

8 replies on 1 page. Most recent reply: Sep 23, 2003 4:26 PM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 8 replies on 1 page
sabab

Posts: 34
Nickname: sabab
Registered: Aug, 2003

JDBC Current Date Posted: Sep 22, 2003 11:25 AM
Reply to this message Reply
Advertisement
I wants to check the CurrentDate(MM/DD/YYY format) with the date in MSSQL Server Database, but my query is not giving the prper result
Anybody knows how to get CurrentDate(in MM/DD/YYYY format Time is not required) in Java, so that can use in my query i am giving my code below

Connection con1;
PreparedStatement stat1;

con1=DriverManager.getConnection ("jdbc:odbc:ENABLE","elearn","hclinfo");
stat1=con1.prepareStatement("select Conf_Id from Conf_Ann where Conf_Cxo=? and Conf_Dt=?"); stat1.setString(1,UData.Uid);
stat1.setDate(2,new java.sql.Date(new java.util.Date().getDate()));
ResultSet result1=null;
result1=stat1.executeQuery();

pls help, urgent!!!!!


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: JDBC Current Date Posted: Sep 22, 2003 3:43 PM
Reply to this message Reply
stat1.setDate(2,new java.sql.Date( System.currentTimeMillis()));

or

stat1.setDate(2,new java.sql.Date( new java.util.Date().getTime() ));

shoud work I guess

sabab

Posts: 34
Nickname: sabab
Registered: Aug, 2003

Re: JDBC Current Date Posted: Sep 23, 2003 6:01 AM
Reply to this message Reply
Thanx for ur suggestion,

but this will give out put in YYYY - MM - DD format right?
How can i convert this to MM/DD/YYYY format ??

pls suggest

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: JDBC Current Date Posted: Sep 23, 2003 6:57 AM
Reply to this message Reply
I don't think there is any format the Date class stores the date. It stores in milliseconds. Anyway why you need to format it? What is the database you are using?

sabab

Posts: 34
Nickname: sabab
Registered: Aug, 2003

Re: JDBC Current Date Posted: Sep 23, 2003 10:34 AM
Reply to this message Reply
I am using MS SQL Server 2K,Actually what is happening is,my table is storing date only (ie 9/23/2003 will be rounded to 9/23/2003 00:00:00) not date with time.So when i am comparing the Date in my Table with current date from java with time (ie, 9/23/2003 Vs 9/23/2003 11:30:58) obviously it will not be equal, i need to compare dates only, i am not considering time

hope that u r clear?

sabab

Posts: 34
Nickname: sabab
Registered: Aug, 2003

Re: JDBC Current Date Posted: Sep 23, 2003 10:40 AM
Reply to this message Reply
I am using MS SQL Server 2K,Actually what is happening is,my table is storing date only (ie 9/23/2003 will be rounded to 9/23/2003 00:00:00) not date with time.So when i am comparing the Date in my Table with current date from java with time (ie, 9/23/2003 Vs 9/23/2003 11:30:58) obviously it will not be equal, i need to compare dates only, i am not considering time

i want to chek whether Today's date is equal to or not equal to the date in database, it should not consider the time


hope that u r clear?

sabab

Posts: 34
Nickname: sabab
Registered: Aug, 2003

Re: JDBC Current Date Posted: Sep 23, 2003 10:44 AM
Reply to this message Reply
I am using MS SQL Server 2K,Actually what is happening is,my table is storing date only (ie 9/23/2003 will be rounded to 9/23/2003 00:00:00) not date with time.So when i am comparing the Date in my Table with current date from java with time (ie, 9/23/2003 Vs 9/23/2003 11:30:58) obviously it will not be equal, i need to compare dates only, i am not considering time

i want to chek whether Today's date is equal to or not equal to the date in database, it should not consider the time

hope that u r clear

zenykx

Posts: 69
Nickname: zenykx
Registered: May, 2003

Re: JDBC Current Date Posted: Sep 23, 2003 3:31 PM
Reply to this message Reply
I don't really understand the question. You may try to create a Date object starting with Calendar.getInstance() and then setting in this Calendar object only the times you require. Eg.
Calendar now = Calendar.getInstance();
now.set(Calendar.MINUTES,0);
....
Date datNow = now.getTime();

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: JDBC Current Date Posted: Sep 23, 2003 4:26 PM
Reply to this message Reply
in Oracle there are functions like to_date() and to_char() for date manupulation. I used those to cut off the time part and make a Srting comparison. Is there any functions equal to those in MS SQL?

Flat View: This topic has 8 replies on 1 page
Topic: Help needed with inheritance!! Previous Topic   Next Topic Topic: javaScript problem!!!!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use