Compare only DATE portion of a datetime field in Expression builder

Hi! All,
This may be a simple question, but I couldn't find the answer. I have a query where I want to say :
Expression exp = exp1.get("startDateTime").equal(pDate);
here pDate is a java.util.Date class with a time stamp.
I wish to basically compare just the DATE portion of the value stored in the data base with only the DATE portion of "pDate" and ignore the time component.
How do I do this in expression builder?
By the way we are on Toplink 9.0.4.5
Thanks

There are a couple of ways to accomplish this. You could use between(beginningOfDay,endOfDay) where beginning of day is 12:00:00am on the date specified in pDate and end of day is 11:59:59pm on pDate. Or you could consider using a combination of dateName(), datePart(), and/or truncateDate() expressions to compare at the day, month, year level. I am not sure which would give you better performance, so you might need to do some testing to verify.
In the first case, create beginningOfDay and endOfDay based upon the date housed in pDate. Then:
Expression selectionCriteria = exp1.get("startDateTime").between(beginningOfDay,endOfDay);
In the second case, there would be a little more code to write:
Expression startDateTimeExp = exp1.get("startDateTime");
Expression dayExp = startDateTimeExp.datePart("day");
Expression monthExp = startDateTimeExp.datePart("month");
Expression yearExp = startDateTimeExp.datePart("year");
int desiredDay = get day of month from pDate;
int desiredMonth = get month of year from pDate;
int desiredYear = get year from pDate;
Expression selectionCriteria = dayExp.equal(desiredDay).and(monthExp.equal(desiredMonth)).and(yearExp.equal(desiredYear));
Check out the TopLink API docs on the Expression class for more details on what these Expression building methods do : http://download-west.oracle.com/docs/cd/B10464_05/web.904/b10491/index.html
Hope that helps,
Doug

Similar Messages

  • Comparing the time portion of datetime items on my form

    Hi. I'm attempting to compare some datetime items on my form. On my form these items are formatted as HH12:MIPM even though they contain a datetime value. I believe my IF statement is failing because the date portion of the datetime values is different.
         if :cc_call_lists.NBT_LOCALDATETIME between :nbt_best_call_tm_start and :NBT_BEST_CALL_TM_END thenIs there a way form me to make this comparison using only the time portion of the datetime value?
    So I need my IF statement to fire even when :cc_call_lists.NBT_LOCALDATETIME is 05/01/2013 02:00PM, and :nbt_best_call_tm_start is 05/15/2013 12:00PM and :NBT_BEST_CALL_TM_END is 05/15/2013 04:00PM.
    Any help would be greatly appreciated. Thanks.

    You have to eleminate the date-part for both items, maybe something like this:
    -- check if first time is smaller second time
    IF (:THEFIRSTDATE-TRUNC(:THEFIRSTDATE)) < (:THESECONDDATE-TRUNC(:THESECONDDATE)) THEN

  • SharePoint Bug? Conflict Error when saving a Page with a "Required" DateTime field in the page layout

    Hello,
    I've just recently encountered a weird error / bug in SharePoint. Here is the scenario:
    - I have a custom column "Test Date" that is of DateTime field type. The field is configured as REQUIRED.
    - It is added to a custom Content Type "Test CT" that is based on a "Publishing Page" content type
    - I have created a Page Layout "Test PL" which is based on that particular content type.
    Now here is what happens:
    1. I try to create a page based on both that Content Type and Page Layout in the Pages Library. I manage to create it successfully.
    2. However, when I go to try and edit the page, fill-in the required values and try to save it using the PAGE TAB -> SAVE BUTTON, I get the below error/s. Note that this happens no matter what I choose in the drop-down menu for Save Button.
    "The file XXX has been modified by USER on DATE"
    But I know I am the ONLY user modifying the page. 
    If I try to save again it gives me options to whether Discard my Changes, Keep Editing, Overwrite Changes, or Merge.
    3. HOWEVER, if I use the Save button on the UPPER RIGHT corner of the screen (the shortcut). I am able to save successfully without any errors!
    The only thing I've tried that made it work was if I made the DateTime OPTIONAL. But I need it to be REQUIRED.
    Is there any workaround to this error / bug?
    Thanks

    I have some additional info but nothing really good. 
    If you click the Save in the left side of the Ribbon then it looks like that is when you get the message. If you click the Save in the top right corner you won't get the message. They must be calling different saving functions. 
    There really is no way around it other than making the field optional which probably removes some server side validation checks causing that message.
    We've chosen to remove that field from the page as I needed it required, then they can't publish the page until they go to the properties and set the article date. By removing the field from the page layout the message goes away.
    I hope MS will fix this at some point.
    -tom daly

  • Comparing of dates

    Hi ,
    If i would need to compare dates do i actually have to use the to_char function ?
    i have tried using field1 < sysdate and it seems to return me the correct data i just dun quite understand why the existing script is using to_char(field1 , 'DDMMYYYY HH24:MI:SS')
    questions :
    1. is there any difference in using to_char
    2. and will it really compare as date format or as string (and thus causing inaccuracy ) ?
    pls advise
    tks & rdgs

    hi
    using to_char(field1 , 'DDMMYYYY HH24:MI:SS')here if u compare only date to date field there is no use of to_char or any other conversion function... but if u using date with format that time u must use to_char bcoz the date format is character there u need to change in date format that's why u use it...
    some thing happen in any other relation like number to character,,,,character to date,,,,date to number... in sql books there are alots of conversation function...
    u read them its very important....for developer and dba's
    Mohammadi
    Oracle DBA

  • AppServ Control keeps mangling dateTime fields in WS tests

    I've deployed a web service that takes 2 dateTime fields as parameters. The format of the dateTime fields is xsd:dateTime (YYYY-MM-DDTHH:mm:ss.SSS).
    However, every time I type in a value in the datTime form field, and press the Invoke button, the AS Control mangles the date into a weird format like YYYY-MM-DDTHH:mm:ss.SSS+X.XXX, and the invoke fails with the error message 'Not all form values are valid."
    How do I bypass this bug? Without it, I can't test the web service using the AS Control.

    I'm testing a web service using the ASC.
    The ASC automatically creates a web page with a form in it to enter my test data.
    For a dateTime field, the "helpful" text next to the field's edit box says "xsd:dateTime (YYYY-MM-DDTHH:mm:ss.SSS)"
    So I type in 2007-07-10T23:12:10.000.
    Until this point, the color of the text in the field is "black" to indicate that the syntax is okay.
    I then change focus so that my cursor is in the next field. Or I press the Invoke button... same thing.
    The contents of the dateTime field automatically change to:
    2007-07-10T23:12:10.000-08.0:00
    and the color of the text in the field turns to "red" to indicate that the syntax is bad. And below the Invoke button I see a message that says:
    "Not all form values are valid."
    I try to change the value back to what it was, but the ASC insists on changing it back to the bad value each time I press Invoke or shift focus away from the dateTime field.

  • Datetime Items - Comparing only the Time portion

    Hi. I have two Datetime items on my form and I need to only compare just the time portion (hh:miPM) of each against each other. None of the other date information is important to me in the comparison. Is there a way to compare just the time portion of each in an IF condition similar to what I have below? Any help would be greatly appreciated.
    For example:
    IF :induction_info.mf_time <> :induction_info.cbms_mf_time THEN
    ....

    You could covert the date-portion to a number like
    IF TO_NUMBER(TO_CHAR(:induction_info.mf_time, 'HH24MISS'))!=TO_NUMBER(TO_CHAR(:induction_info.cbms_mf_time, 'HH24MISS')) THEN
    ..If you just want to check for "unequal", you could even leave the TO_NUMBER-part

  • SQL: comparing date with datetime field

    I'm having a brain fart as I assume this is really simple.
    Given that I have the date in the format of yyyy/mm/dd, how
    do I put that
    into a sql query that compares that to the datetime field?
    It appears the datetime field, by default, uses this format:
    m/d/yyyy
    hh:mm:ss am
    -Darrel

    If your date formats are different you will have to use CAST
    or CONVERT
    functions as you state you already have. If this works then
    stick with it.
    You may also need to use a SET DATEFORMAT command. See below:
    http://msdn2.microsoft.com/en-us/library/ms189491.aspx
    Dates in SQL Server can be a bit of a pain to work with. It
    is usually best
    practice to store your DateTime data in raw format and use
    CAST or CONVERT
    functions in your Stored Procs to get the correct results.
    Pat.
    "darrel" <[email protected]> wrote in message
    news:ftloim$jv4$[email protected]..
    >
    >> What dbms?
    >
    > t-sql (MSSQL)
    >
    > For now, via string functions, I rearrange the date/time
    format manually,
    > and then use the CAST statement in the SQL query. Not
    pretty, but seems to
    > work.
    >
    > -Darrel
    >

  • Accessing data in a MS Access DATETIME field

    Can anybody please tell me how to retrieve and update data in a DATETIME field from a table in MS Access Database? (I have a JDBC connection and can query/update other fields, but not this one)
    thx

    For retrieving, use rs.getString("FIELD_NAME") or rs.getString(COLUMN_NO) method. For updating and/or inserting, use single quots('...') and proper datetime format.

  • Datetime field overflow / String data right truncation

    Hi All,
    Getting the follwing erros while working with timestamp for selecting from or inserting data into DB2 through WebSphere 6.1.
    I am passing values like this: 2006-05-02-21.57.26.744341.
    The queries run fine while executing through some SQL Frontend editor.
    [IBM][CLI Driver] CLI0114E Datetime field overflow. SQLSTATE=22008
    [IBM][CLI Driver] CLI0109E String data right truncation. SQLSTATE=22001
    Please let me know the problem.

    If you are trying to convert to a java.sql.Timestamp as part off the process of inserting into DB2 then Timestamp is derived from java.util.Date which holds the time in milli-seconds but you are providing a microseconds field.
    Could this be the problem?

  • How to delete only a portion of the data portal?

    This would be similar to DataDelAll() command, but allow only a limited set of data to be removed.
    For some background:
    - DIAdem 9.1 sp2
    - LabVIEW interface calling various DIAdem/VBS scripts
    Using DIAdem to format reports based on various scripts and TDM data
    results, I would like to be able to load and unload various data files
    (TDM) while maintaining the specific report layout (also TDM) data in
    the portal.  Two (ugly) options seem to be:
    a)  load entire data result set into the portal (including layout instructions) and process, or
    b)  keep track of layout state variables and clear portal/reload layout/load next data
    This would all be easy if there is a command to enable the right-click delete... behavior of the data portal UI.
    Thanks!
    James

    Hello James,
    there are diufferent commands you can use to delete only a portion of the data in the portal. You can delete single channels, a selection of channels, or entire groups with these three commands:
    Call ChnDel(ChnArg) - deletes one channel
    Call ChnDelete(ClpSource) - deletes a selection of channels
    Call ChnSDel(ChnArg1, ChnNo) - delets a number of channels
    Call GroupDel(TargetGroupIndex) - deletes a group including its channels
    To create a selection of channels as argument for the second command, have a look at the functions
    ChnSelAdd, ChnSelGet, ChnSelCount
    Regards
    Ingo Schumacher
    Systems Engineer Sound&VibrationNational Instruments Germany

  • How to compare table data and table field

    Hi buddy,
        I have some question about how to compare table data and table field.
       1. I know there is one method:   CL_ABAP_UNIT_ASSERT=>ASSERT_TABLE_CONTAINS  , it use in unit test to compare the table data(A and B) , you can loop table A into structure A1, then use this mehtod it can compare whether table B contain structure A1.  but when I try to use this in main program it will dump.
              CL_ABAP_UNIT_ASSERT=>ASSERT_TABLE_CONTAINS(
                                                                                                        LINE    = A1
                                                                                                        TABLE = B ).
           Is there any method or FM can be used to compare the table data ?
        2. I also want to compare two table field , try to find out the different. How to realize this.
    Thank you for your sincerely answer.

    Hi Zongjie,
    What`s the difference, if you using loop A into wa_A, read table B into wa_B with all field, then compare with wa_A and wa_B.
    The question 2, seems no standard FM available here.
    Loop A into wa_A.
       Loop B into wa_B.
           if wa_A-field1 eq wa_B-field1.
           endif.
            if wa_A-field2 eq wa_B-field2. 
           endif.
       endloop.
    endloop.
    regards,
    Archer

  • Concatenate date time and update SQL datetime field

    I have a form that captures date and time in 2 separate fields data and time.
    I need to combine these fileds and UPDATE a SQL database (datetime field)
    The date field is passed like this  DSDATE={ts '2013-11-18 00:00:00'}
    The time field is passed like this   TIME_IN1=14:05
    How do I concatenate DSDATE AND TIME_IN1 so that I can insert like this 2013-11-18 14:05:00.000 ?

    The easiest way may be the best. You judge.
    <cfset DSDATE = parsedatetime('2013-11-18')>
    <cfset  TIME_IN1="14:05">
    <cfset yr = year(DSDATE)>
    <cfset mnth = month(DSDATE)>
    <cfset d = day(DSDATE)>
    <cfset hr = listGetAt(TIME_IN1,1,":")>
    <cfset mn = listGetAt(TIME_IN1,2,":")>
    <cfset datetime=createdatetime(yr,mnth,d,hr,mn,0)>
    <cfoutput>#datetime#</cfoutput>

  • Mysql datetime datatype, from that datetime how can i compar only time part

    Hello i have database table in mysql, there is Datetime datatype column, from that datetime how can i compare only time part .....??
    Thanks in advance...

    Note you can't simply just compare time via equality however.
    Timestamp resolution is to the second or even milli-second. No user wants to match a time to an exact millisecond.
    What they want is something like a match by hour - for example returning the number of transactions that happened from 1pm to 2pm. Even that isn't completely correct because then you need to consider whether 1pm and/or 2pm is inclusive or exclusive. Normally one end will be inclusive and the other exclusive.
    So first you need to define what the period is.
    Then construct the range.
    Then pass the range and, as already mentioned, use specific functions to handle the extraction of the time.

  • Compare times (not only date! minutes too!)

    is there already a method to compare two dates and to return the date
    "space" between them? I mean, there's the compareTo(Date d) thing but it returnes the number of days as an int..
    help?! :D

    Calendar. Or do it yourself by using the longs.

  • How can I create an index on the date part of a timestamp field?

    is there a way I can create an index on the date part of a timestamp field?

    LONGENECKER wrote:
    Idea:
    If you find no direct command that allows you to create an index on JUST the date portion of a timestamp datatype column then I recommend you consider splitting date and time into two seperate columns.
    If date is column "A" and time is column "B" then you can concatenate them using a view or virtual column (in 11G) to re-assemble them at run time.
    In the solution I describe above you might trade ease of management for better performing queries.
    Additional Info:
    This thread may be of some value.
    Can we create INDEX on TIMESTAMP column???
    And what datatype do you propose for your columns A and B? The only proper datatypes would be DATE or TIMESTAMP. Both of these inherently carry both date and time components, so that would have to be dealt with anyway. The use of any character or number datatype to hold date and/or time should be treated with an application of Billy's lead pipe.
    Perhaps function based indexes would be a better solution.

Maybe you are looking for

  • Why is Encore 5.1 AUTO mode building files just a bit too large for DVDs?

    I've been doing the same videos for a few years using Encore 1.5 and more recently Encore 5.1 (with Premiere 5.5).  The videos are typically football games with short 2-25 secs of motion menus.  If I put two games per DVD, the total running time has

  • Menu defaults to widescreen in Encore CS4

    Hello all! I've looked this question up a bunch of different ways on this forum, and haven't seen it asked, so I figured I'd ask it. I am working on a full-screen program for a client, and brought in a full-screen PSD menu. It is in proper 4:3 ratio,

  • Selection Screen Differences in 3.5 Vs 7.0

    Hi Friends ,                    I see some differences in the Selection Criteria screens when compared to 3.5 Vs 7.0, Is this how they are supposed to be , is there any relevan notes which describes all the differences between 3.5 and 7.0 ? thanks in

  • Error calling background engine!!!

    Hi guys!! can you help me??? Status row for item 'WFEVDEME/PO345345', activity ID '228' This is the error when i4m launching the background engine!!! The Item Type WFEVDEME doesn4t exists.Why the sqlplus are returning this error???? cheers

  • Help creating an array from a list of vector item

    I am writing a Email Handling class that uses an Email class that I have already written. The spec requires me to (A.) Create a DisplayEmail(Email[] e) method that takes and array of email messages and displays them in the terminal window. And then (