You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Phillip Rhodes <sp...@rhoderunner.com> on 2003/02/14 15:59:20 UTC

Need simple Date Criteria example please...

Sorry, but spent several hours on this...  and 30+ minutes on the mailing
list archives looking...

I am using the tdk 2.1
I have a column defined as a date in the schema file.
When I add the java date object to the criteria object, it generates sql
that does not compare to the date that is stored in the database.  So I
never get records back from my select statement.

I also tried timestamp, that did not work either.
Sorry I am slim on details, but my files are at home.
I was hoping to get an example of how to do a select on a table with the
date field in the criteria...

I have a column with a date.  Closest precision is day of the month.  Time
is not important.

String mydatestring = "2002-04-03";
String format = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date mydate = sdf.parse(mydatestring);
criteria.add(SamplePeer.DATE_COL,mydate);

Thanks.  Getting this out there now so I don't have to hang over the weekend!








---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Need simple Date Criteria example please...

Posted by Fabio Daprile <fa...@wuerth-phoenix.com>.
Hello,

hereafter a short example of dates in criterias.
Hope this helps.
Greetings  Fabio Daprile

                  case DATE_PARAM:
                    _criterions = new Vector();

                    for (int i = 0; i < _searchTermsList.size(); i++)
                    {
                      SearchTerm _sTerm = 
(SearchTerm)_searchTermsList.get(i);
                      _dateTemp = (_sTerm.getValueAsDate(1).getYear()  + 
1900) + "-" + (_sTerm.getValueAsDate(1).getMonth() + 1) + "-" + 
_sTerm.getValueAsDate(1).getDate();
                      
//System.out.println(_sTerm.getValueAsDate().toString());
                      //System.out.println(_dateTemp);

                      if (_sTerm.getType().equals("STARTED"))
                      {

                        if (_sTerm.getOperator().equals("ON"))
                        {
                          _criterion = 
_criteria.getNewCriterion(TicketsPeer.STARTEDTIMESTAMP,
                                                                
_dateTemp + " 00:00:00",
                                                                
Criteria.GREATER_EQUAL);
                          
_criterion.and(_criteria.getNewCriterion(TicketsPeer.STARTEDTIMESTAMP,
                                                                
_dateTemp + " 23:59:59",
                                                                
Criteria.LESS_EQUAL));
                        }
                        else if (_sTerm.getOperator().equals("AFT"))
                          _criterion = 
_criteria.getNewCriterion(TicketsPeer.STARTEDTIMESTAMP,
                                                                _dateTemp,
                                                                
Criteria.GREATER_THAN);
                        else if (_sTerm.getOperator().equals("BEF"))
                          _criterion = 
_criteria.getNewCriterion(TicketsPeer.STARTEDTIMESTAMP,
                                                                _dateTemp,
                                                                
Criteria.LESS_THAN);
                        else if (_sTerm.getOperator().equals("BETWEEN"))
                        {
                          _dateTemp2 = 
(_sTerm.getValueAsDate(2).getYear()  + 1900) + "-" + 
(_sTerm.getValueAsDate(2).getMonth() + 1) + "-" + 
_sTerm.getValueAsDate(2).getDate();

                          _criterion = 
_criteria.getNewCriterion(TicketsPeer.STARTEDTIMESTAMP,
                                                                _dateTemp,
                                                                
Criteria.GREATER_THAN);
                          
_criterion.and(_criteria.getNewCriterion(TicketsPeer.STARTEDTIMESTAMP,
                                                                _dateTemp2,
                                                                
Criteria.LESS_THAN));
                        }
                        _criterions.add(_criterion);
                      }

Phillip Rhodes wrote:

>Sorry, but spent several hours on this...  and 30+ minutes on the mailing
>list archives looking...
>
>I am using the tdk 2.1
>I have a column defined as a date in the schema file.
>When I add the java date object to the criteria object, it generates sql
>that does not compare to the date that is stored in the database.  So I
>never get records back from my select statement.
>
>I also tried timestamp, that did not work either.
>Sorry I am slim on details, but my files are at home.
>I was hoping to get an example of how to do a select on a table with the
>date field in the criteria...
>
>I have a column with a date.  Closest precision is day of the month.  Time
>is not important.
>
>String mydatestring = "2002-04-03";
>String format = "yyyy-MM-dd";
>SimpleDateFormat sdf = new SimpleDateFormat(format);
>Date mydate = sdf.parse(mydatestring);
>criteria.add(SamplePeer.DATE_COL,mydate);
>
>Thanks.  Getting this out there now so I don't have to hang over the weekend!
>
>
>
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>  
>

-- 
************************************
Würth Phoenix S.r.l.
Fabio Daprile

Via Kravogl 4
I-39100 Bolzano
Phone: +39 0471  564111 (direct 564066)
Fax: +39 0471  564122
mailto:fabio.daprile@wuerth-phoenix.com
http:// www.wuerth-phoenix.com
*************************************




---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org