You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Scott Eade <se...@backstagetech.com.au> on 2002/09/04 01:28:24 UTC

Re: Date comparison

> From: Alexander Banthien <al...@questech.de>
> 2. For Crteria with date comparisons refer to a mail a few days back on this
> list something similar to
> ------------------------------------------
> Criteria crit = new Criteria();
> java.sql.Date sqlDate = new java.sql.Date((new Date()).getTime());
> crit.add(MyPeer.SEND_DATE,sqlDate,Criteria.LESS_THAN);
> List list = MyPeer.doSelect(crit);
> --------------------------------------------
> will do the job for you. Refer to 1 for improvement of the example code :-)

Another perhaps more convenient approach is to make use of CURRENT_DATE
(ANSI SQL).  First you need to define a constant somewhere (for now lets say
in MyAppConstants):

public static final Object CURRENT_DATE = (new Object() {
    public String toString()
    {
        return "CURRENT_DATE";
    }
});

You can then use this in your Criteria:

criteria.add(MyPeer.START_DATE, MyAppConstants.CURRENT_DATE,
Criteria.LESS_EQUAL);

Currently I define CURRENT_DATE in my application equivalent of
TurbineConstants. If the torque test bed ever gets going again ( ;-) I know
Stephen, we're waiting for maven b7) I will provide a patch to add this
constant to the Criteria class itself.

HTH,

Scott
-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Date comparison

Posted by Keshava Murthy <ke...@bigtec.org>.
Hi Nataraj,
Thanks for your response.
I solved this by using the method - Date.valueOf(String str). Do you think
the method you defined will be more useful if I require to save time along
with Date.

regards,
keshav
----- Original Message -----
From: "K Nataraj" <kn...@prodapt.com>
To: "'Turbine Users List'" <tu...@jakarta.apache.org>
Sent: Wednesday, November 13, 2002 6:06 PM
Subject: RE: Date comparison


> U can get the the date from VM like this..
>
> String date = parser.get("dateField");
>
> this u can convert to java.sql.Date using the
> SimeplDateFormatter class of java.text package .,
>
>
> a sample goes like this
>
>  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // This
> yyyy-MM-dd is configurable..Refer jdk  // //documentation for futher
> details..
>  ParsePosition position = new ParsePosition(0);
>  java.sql.Date date = (java.sql.Date)
dateFormat.parse(dateString,position);
>  return date;
>
>
> Now u can compare the values as u wish..Hope this helps...
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Date comparison

Posted by Keshava Murthy <ke...@bigtec.org>.
Hi,
I tried to use the method you sugested, but the line
"java.sql.Date date = (java.sql.Date)
dateFormat.parse(dateString,position);"
is throwing java.lang.ClassCastException: java.util.Date.

Can you tell me how to get sql Date object ?

regards,

Keshava Murthy. S



----- Original Message -----
From: "K Nataraj" <kn...@prodapt.com>
To: "'Turbine Users List'" <tu...@jakarta.apache.org>
Sent: Wednesday, November 13, 2002 6:06 PM
Subject: RE: Date comparison


> U can get the the date from VM like this..
>
> String date = parser.get("dateField");
>
> this u can convert to java.sql.Date using the
> SimeplDateFormatter class of java.text package .,
>
>
> a sample goes like this
>
>  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // This
> yyyy-MM-dd is configurable..Refer jdk  // //documentation for futher
> details..
>  ParsePosition position = new ParsePosition(0);
>  java.sql.Date date = (java.sql.Date)
dateFormat.parse(dateString,position);
>  return date;
>
>
> Now u can compare the values as u wish..Hope this helps...
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Date comparison

Posted by K Nataraj <kn...@prodapt.com>.
U can get the the date from VM like this..

String date = parser.get("dateField");

this u can convert to java.sql.Date using the
SimeplDateFormatter class of java.text package .,


a sample goes like this

 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); // This
yyyy-MM-dd is configurable..Refer jdk  // //documentation for futher
details..
 ParsePosition position = new ParsePosition(0);
 java.sql.Date date = (java.sql.Date) dateFormat.parse(dateString,position);
 return date;


Now u can compare the values as u wish..Hope this helps...




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Date comparison

Posted by Keshava Murthy <ke...@bigtec.org>.
Hi,

I would like to convert string obtained from vm file (format = dd/mm/yyyy
and dd/mm/yyyy  hh24:mi) to java.sql date and compare this against a field
in oracle database.

Could some one tell me how this can be done?

regards,
Keshava Murthy


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>