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]

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"";
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 >

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;
Ok that doesent solve my problem as much as i apprichiate your answer. Could you be a bit more specific please.
I am using Access 2002 ... and not oracle ;( so that is my problem.
> 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 >

Doesn't Access have a built-in function Date()?
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.
> 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.
> 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 >

> > 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());
Doesn't MS SQL / Access have a getdate() function? Why not just use that?SELECT * FROM WHATEVER WHERE DATE < GETDATE()