Getting Current Date and using it in SQL

How do you get a current time and store it in a variable..

I am trying to make an a SQL query using it to search for all previous days appart from today.

ex:

currentDate =// store current date as a ShortDate into a variable

query ="SELECT * FROM Table WHERE < DATES "+currentDate+" ORDER BY Id"";

[438 byte] By [brokolyx] at [2007-9-30 18:24:07]
«« JNDI Cast
»» repaint
# 1

Sorry i made an error in the query. Here is the correct query.

currentDate = // store current date as a ShortDate into a variable

query = "SELECT * FROM Table WHERE DATES < "+currentDate+" ORDER BY Id"";

brokolyx at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 2
Hi,Create a prepared statement instead of a normal statement. The prepared statement has a method to set dates etc./Kaj
kajbj at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 3
You can get today's date (current date/time) in oracle as suchSELECT TO_CHAR(SYSDATE, 'LOOK-AT-DOCS-FOR-YOUR-FAVORITE-FORMAT-HERE')FROM SYS.DUAL;
filestream at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 4
Ok that doesent solve my problem as much as i apprichiate your answer. Could you be a bit more specific please.
brokolyx at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 5
I am using Access 2002 ... and not oracle ;( so that is my problem.
brokolyx at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 6

> Ok that doesent solve my problem as much as i

> apprichiate your answer. Could you be a bit more

> specific please.

Well... hmm.. I thought that you would check the documentation for PreparedStatement, or search the forum, but it doesn't look like you want to do that:

http://forum.java.sun.com/thread.jsp?forum=31&thread=495267

/Kaj

kajbj at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 7
Doesn't Access have a built-in function Date()?
filestream at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 8
Regarding prepared statement .I am trying to insert the date into a variable like below.String date = new java.sql.Date(myDate.getTime());I want allow me .... there really has to be a way to get a current System Date within java.
brokolyx at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 9
> I want allow me .... there really has to be a way to> get a current System Date within java.Sure, there are a number of ways. Using java.util.Calendar, using java.util.Date, using java.lang.System.
filestream at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 10

> Regarding prepared statement .

>

> I am trying to insert the date into a variable like

> below.

> String date = new java.sql.Date(myDate.getTime());

>

> I want allow me .... there really has to be a way to

> get a current System Date within java.

That is because you have a lot of errors in that line..

java.sql.Date now = new java.sql.Date(System.currentTimeMillis());

If you want it as a sql date object (date object in sql doesn't have a time field, you need to use Timestamp if you want date and time)

/Kaj

kajbj at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 11

> > Regarding prepared statement .

> >

> > I am trying to insert the date into a variable

> like

> > below.

> > String date = new

> java.sql.Date(myDate.getTime());

> >

> > I want allow me .... there really has to be a way

> to

> > get a current System Date within java.

>

> That is because you have a lot of errors in that

> line..

>

> > java.sql.Date now = new

> java.sql.Date(System.currentTimeMillis());

>

>

> If you want it as a sql date object (date object in

> sql doesn't have a time field, you need to use

> Timestamp if you want date and time)

>

> /Kaj

java.sql.Date now = new java.sql.Date(new java.util.Date().getTime());

hfahimi.com at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...
# 12
Doesn't MS SQL / Access have a getdate() function? Why not just use that?SELECT * FROM WHATEVER WHERE DATE < GETDATE()
Navy_Coder at 2007-7-6 19:34:26 > top of Java-index,Java Essentials,Java Programming...