Handling DATE and TIME in SELECT Statment

Hey pros,
I have this problem where I want to execute a select query based on date and time, but I want it to be handled in such a way which is better explained with this example:
User enters a date range of Apr. 10 and Apr. 12
User enters a time range of 9:00am - 10:00am
The results I want would be from April 10 9:00am to Apr. 12 10am.
The way I have it working today is that it shows me all data from Apr. 10-12 from 9am-10am on all days.
Is there an easy way to do this?
Here is my code (see the 3rd last and 2nd last line)  Thanks!
SELECT vepowerks vepolgort vepo~matnr
          mara~mtart
          vepovenum vepovepos
          vekperdat vekperuhr vekpstatus vekpexidv
          "gc_bwart as bwart
          vepovemng vepovemeh
          vepo/cwm/vemng vepo/cwm/vemeh
    INTO CORRESPONDING FIELDS OF TABLE gt_tran
INTO CORRESPONDING FIELDS OF TABLE itab
    FROM vepo
      INNER JOIN vekp ON
          vepovenum = vekpvenum
      INNER JOIN mara ON
          vepomatnr = maramatnr
    WHERE
          vepo~werks = p_werks    AND
          vepo~lgort IN s_lgort   AND
          vepo~matnr IN s_matnr   AND
          vepo~bestq = gc_bestq   AND
          NOT ( vepovemng = 0 AND vepo/cwm/vemng = 0 ) AND
          vekp~status = gc_status AND
          vekp~erdat IN s_erdat   AND
          vekp~eruhr IN s_eruhr   AND
          mara~mtart IN s_mtart.

I think you might just have to select the date range, then do a loop and read table.
select xx where date in date_range from x into table y.
loop at y into wa_y.
  if wa_y-date = lower_date_limit. "this day has the 9am limit
    "only pick those records that have wa_y-time GE 9am.
    <your logic here>
  elseif wa_y-date = upper_date_limit. "this day has teh 12pm limit
    "only pick those records that have wa_y-time LE 12pm.
    <your logic here>
  else. "every day in between the dates
    "get all data no matter what the time is
    <your logic here>
  endif.
I honestly don't know if there is a select-where clause that will do this automatically, but the above solution should work..hope this helps.
--Juan
Edited by: takeabyte on Apr 29, 2010 8:36 PM

Similar Messages

  • How do you handle date and time in a global implementation

    Hello:
    Does somebody have a strategy on handling date and time in a global environment? Does Oracle timestamp it based on the Time Zone it is in? If so, if I have a distributed data architecture and data is getting replicated across these sites that are in different time zones, how does it handle the situation?
    Thanks.
    venki

    There are a variety of TIMESTAMP data types-- TIMESTAMP, TIMESTAMP WITH TIME ZONE, and TIMESTAMP WITH LOCAL TIME ZONE. TIMESTAMP WITH TIME ZONE or TIMESTAMP WITH LOCAL TIME ZONE will probably work for you. If you are going to display the data to a user, however, TIMESTAMP WITH LOCAL TIME ZONE is probably the best option since it automatically converts to the local time zone. If you just have application code that is looking at the timestamps, either one will work.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • HOW: File handling - Date and time of file created/modified

    Hi all,
    Is there any way by which we can find out the date and time of the file created in operating system using file handling through PL/SQL.
    Eg:-
    I have a directory in which I am storing some files, and for a given file name I must know when that file was created, i mean date and time.
    Might be there is some simple way, please help out.
    regards
    CJ

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:439619916584#73995149457661
    Remember to get the correct privs (java privs) on the directory.
    Mette

  • Job created date and time.

    hi,
    I am created the job with single step of program.
    my problem is, i am passing the job DATE and TIME to select query in the program.
    when ever job is execute ,what ever records in the table it is retrived,sometime job abends ,we restart the job,it is retrive the records from the last date and time.
    but it is not happening now ,can you help me.
    for the following query.
    select aufnr from z<table> where created_date = SDLDATE
                                                    created_time = SDLtime.

    Hi,
    perhaps, your query is not correct? It should be
    SELECT ... INTO <work area>
       Please reward points if useful.
                 Kind regards, Marina

  • When I try to adjust the date and time of an event by selecting Photos from iPhoto, the year I enter is altered.

    I have images in iPhoto from an older digital camera which did not record the date and time.  In iPhoto, with an event selected, I have tried to adjust the date and time by choosing Photo.  When I adjust the date and check Modify original files, it makes the date much earlier--in centuries.  I now have an event from August 2003 (the date I entered) which reads June 2, 1251 under the event!  When I attempt to correct it, it goes back further in time.  What am I doing wrong?

    (I use iPhoto only to import from my iPhone; I organize all my images, including thousands of RAW files, in folders on a big external drive.)
    Why are you using iPhoto at all? use image capture or drag and drop the photos
    The problem is that the files I am copying are getting stripped of the EXIF metadata
    eliminating iPhoto from your work flow will eliminate one oppertunity to have this happen  For photos in iPhoto it is best to export them rather than drag an drop them - this assures your EXIF and IPTC data is correct and uptodate
    Why would I be able, over many years, to retain EXIF metadata in photos imported from an iPhone--then one day find that the same workflow strips such photos of EXIF data?
    Because exporting is the supported way to "export" photos - I never drag and drop photos out of iPhoto and I never use thrid party programs on the photos in the iPhoto library - try exporting as suggested above and see if that is the solution
    LN

  • Selection Screen - Date and Time

    Hi,
    I have given a selection screen where the user needs to key in the input in the following format
    dd.mm.yyyy hh:mm:ss.
    Reason is that the database fetching these elements accepts only in this criteria.
    Now as they look into automating this program, they would want to automatically take the current system date and time - 24 hours .
    How do I achieve this in the above format? If this is not possible, let me know if i can make the selection screen with normal sap date format and convert it to the above format on passing to the select statement.
    Regards
    Sam

    Hi Sam,
    See this. Is this your requirement.
    With this we are able to get Current time-stamp to selection parameter.
    REPORT ZTEST.
    DATA: L_TS TYPE TZNTSTMPS,
           L_TS_C TYPE CHAR14.
    PARAMETERS:
    P_TMSTMP TYPE TMSTMP OBLIGATORY MEMORY ID TEST.
    INITIALIZATION.
       GET TIME STAMP FIELD L_TS.
       MOVE L_TS TO L_TS_C.
       SET PARAMETER ID  'TEST' FIELD L_TS_C.
    The output is
    Jogeswara Rao K

  • Show date and time in menu bar won't stay selected

    Using 10.6.7 with all updates as of the time I am writing this.
    Show date and time in menu bar is unselected and unselectable. When I select it (click it) it will unselect itself. I will see the checkmark for 1/2 a second, but won't stay selected.
    I've reparied permissions in the Disk Utility as described by a similar post (on an older version of the OS) with no luck.
    At a little bit of a loss. Spending the mandatory 30 minutes with various forms of Google searches with no luck.
    Looking for new ideas other than an OS restore.
    David

    Looking for new ideas other than an OS restore.
    Restart?

  • Date selection will not print properly when using Microsoft Date and Time Picker Control 6.0 in Excel 2010

    I have created a field input worksheet in which the user identifies start and end dates for training sessions, using the Date and Time Picker Active X Control.  It works fine on-screen, but when the worksheets are printed, the dates that were selected
    using the date picker calendar print out in an unreadable, huge font.  The large font also appears in the print preview mode.  I've tried modifying various properties in design mode, but nothing that I have tried will correct the problem. 
    Any ideas?

    The DTPicker seems to have some bugs in it when used on a worksheet. I have overcome the above by setting the size properties to the same size as a cell and the Linked cell property to the
    cell under the DTPicker. (Even setting the Linked cell had problems with an error message referring to the Check box property to be set to true so I just set it to true and inserted the linked cell and set the checkbox property back to
    false.)
    Then the VBA code below that Hides the DTPicker after a date is selected and unhides the DTPicker when the linked cell with the date is selected. The code is for 2 DTPickers so you will need to edit to suit your requirements.
    Caveat: If the DTPicker is visible then you can't hide it by selecting the same date again. If this occurs then it is a multi step operation. First select another date and the DTPicker will hide, then click on another cell then back on the cell with
    the date to unhide the DTPicker and then select the correct date.
    Hope it helps and feel free to get back to me with any questions etc.
    Private Sub DTPicker1_Change()
        Me.DTPicker1.Visible = False
    End Sub
    Private Sub DTPicker2_Change()
        Me.DTPicker2.Visible = False
    End Sub
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Select Case Target.Address
            Case "$E$5"     'This is the linked cell for DTPicker1
                Me.DTPicker1.Visible = True
            Case "$E$13"    'This is the linked cell for DTPicker2
                Me.DTPicker2.Visible = True
        End Select
    End Sub
    Regards, OssieMac

  • The date and time on my iPhone 5s is incorrect when I select Set Automatically. How can I resolve this?

    My iMessage and FaceTime, among other apps, are unable to activate for some reason. Other forums have suggested I make sure my date and time are correct and are Set Automatically. I noticed that the time zone, date, and time are all incorrect. Any suggestions??

        I'm sorry this is happening, loucm. When did this start? Please try resetting Network Settings. You can go to Settings>General>Reset>Reset Network Settings
    Please keep us posted.
    Thank you,
    VanessaS_VZW
    Follow us on Twitter @VZWSupport

  • Date and Time Issue.

    I have date and time with different format , Need in Single date and Time format.
    Input
    13/03/15 09:09
    13/03/15 07:39
    13/03/15 08:09
    13/03/15 08:51
    3/13/15 09:39:14 AM
    3/13/15 09:38:14 AM
    3/13/15 09:37:59 AM
    3/13/2015 09:37:59 AM
    Problem with the below Output
    01/01/01 12:00 AM
    01/01/01 12:00 AM
    01/01/01 12:00 AM
    01/01/01 12:00 AM
    13/03/15 09:39 AM
    13/03/15 09:38 AM
    Output required in the below format for all of the above date and Time with proper date & time
    13/03/15 09:39 AM

    Indudhar,
    I don't know if the following will help or not, but hopefully you can see what I'm doing and modify it to give you the string format of the DateTime the way you want it:
    ption Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
    Public Enum DateTimeFormat
    LongDateLongTime
    LongDateShortTime
    ShortDateLongTime
    ShortDateShortTime
    LongDateOnly
    ShortDateOnly
    LongTimeOnly
    ShortTimeOnly
    End Enum
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    ' Test it here...
    Stop
    End Sub
    Private Function GetFormattedDateTimeString(ByVal dt As DateTime, _
    ByVal formatType As DateTimeFormat) As String
    Select Case formatType
    Case DateTimeFormat.LongDateLongTime
    Return String.Format("{0} {1}", _
    dt.ToLongDateString, _
    dt.ToLongTimeString)
    Case DateTimeFormat.LongDateOnly
    Return dt.ToLongDateString
    Case DateTimeFormat.LongDateShortTime
    Return String.Format("{0} {1}", _
    dt.ToLongDateString, _
    dt.ToShortTimeString)
    Case DateTimeFormat.LongTimeOnly
    Return dt.ToLongTimeString
    Case DateTimeFormat.ShortDateLongTime
    Return String.Format("{0} {1}", _
    dt.ToShortDateString, _
    dt.ToLongTimeString)
    Case DateTimeFormat.ShortDateOnly
    Return dt.ToShortDateString
    Case DateTimeFormat.ShortDateShortTime
    Return String.Format("{0} {1}", _
    dt.ToShortDateString, _
    dt.ToShortTimeString)
    Case DateTimeFormat.ShortTimeOnly
    Return dt.ToShortTimeString
    Case Else
    Return String.Empty
    End Select
    End Function
    End Class
    I hope that helps. :)
    Still lost in code, just at a little higher level.
    No Frank, Same Problem.....Kindly help me  X1 = 14/03/15 19:30
    I need time Diff of now and X1
    Dim myDateTime As DateTime = GetFormattedDateTimeString(X1, DateTimeFormat.ShortDateOnly)
    myDate = myDateTime.ToString("dd/MM/yy")
    myTime = myDateTime.ToString("hh:mm tt")
    Dim myDateTime1 As DateTime = Now
    Dim myDate1 = myDateTime1.ToString("dd/MM/yy")
    Dim myTime1 = myDateTime1.ToString("hh:mm tt")
    Dim diff As TimeSpan = myDateTime1.TimeOfDay - myDateTime.TimeOfDay
    Dim diffString As String = String.Format("{0:00}:{1:00}:{2:00}", _
    Math.Abs(diff.Hours), Math.Abs(diff.Minutes), Math.Abs(diff.Seconds))

  • Unable to insert date and time when using date datatype

    Hi
    I am hitting a bit of a problem when using the date datatype. When trying to save a row to the table where the field it throws an error ora 01830 and complains about converting the date format picture ends...etc. Now when I do the insert, I use the to_date function with the format of "dd-mon-yyyy hh24:mi:ss". Of course, when I remove the time element, everything is perfect.
    Checking sysdate, I noticed that the time element wasn't be displayed, and I used alter session set nls_date_format to set the date and time I want to save to the table, which worked!
    Then based on advice in a previous thread to permanently fix the problem, I used alter system set nls_date_format ="dd-mon-yyyy hh24:mi:ss" scope=spfile; This showed that it was altered, and I can see the setting in the em. In sqlplus, I shutdown the database, and restarted with startup mount; alter database open; and then selecting sysdate, it still shows the date as dd-mon-yy, and still no time! Checking the em, and looking up the nls_date_format the setting is still shown as "dd-mon-yyyy hh24:mi:ss".
    So, my question is this - what am I doing wrong? Why can't save date and time using date in Oracle 11g?????
    Thanks

    user633278 wrote:
    Hi
    I am hitting a bit of a problem when using the date datatype. When trying to save a row to the table where the field it throws an error ora 01830 and complains about converting the date format picture ends...etc. Now when I do the insert, I use the to_date function with the format of "dd-mon-yyyy hh24:mi:ss". Of course, when I remove the time element, everything is perfect.
    Checking sysdate, I noticed that the time element wasn't be displayed, and I used alter session set nls_date_format to set the date and time I want to save to the table, which worked!
    Then based on advice in a previous thread to permanently fix the problem, I used alter system set nls_date_format ="dd-mon-yyyy hh24:mi:ss" scope=spfile; This showed that it was altered, and I can see the setting in the em. In sqlplus, I shutdown the database, and restarted with startup mount; alter database open; and then selecting sysdate, it still shows the date as dd-mon-yy, and still no time! Checking the em, and looking up the nls_date_format the setting is still shown as "dd-mon-yyyy hh24:mi:ss".
    So, my question is this - what am I doing wrong? Why can't save date and time using date in Oracle 11g?????
    ThanksYou most certainly can save the time. A DATE column, by definition stores date and time. What you describe is a presentation problem, and setting nls_date_format at the system as an init parm is the weakest of all settings as it is overridden by several other locations.
    without seeing the exact sql that produced the error (not just your description of what you think you were doing) it is impossible to say for sure.
    However, I'd suggest you read http://edstevensdba.wordpress.com/2011/04/07/nls_date_format/

  • Need help in using SQL in a jsp file to compare date and time

    hi every one,
    Actually I am doing a project using JSP. I need to compare a date field in the database (MS Acess) to the current system date and time. I have to do this in a select statement.
    I have alredy defined a variable of type Date in the JSP file and I am comparing this variable to the date in the database through a select statemant.
    Here is what I am doing
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
              java.util.Date today = new java.util.Date();
              String myDate=sdf.format(today);
    query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= "+myDate+" ;";
    EDate is the feild in the database and it's format is (5/12/2008 5:29:47 PM) it is of type Date/Time in MS Acess.
    when I execute the query it gives the following error
    SQL error:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'EDate <= 2008-10-16 08:10:07'.
    I hope any one can help me with that error and answer my question, I've tried too many things but nothing helps
    Thanks in advance :-)

    Hi,
    When the comparision is needed to be done with the current date , we don't need to send in Java
    Date then format it and compare with MS Acess Date.
    In MS Access we have Date() function which will give you the current date.
    So you can try rewriting your query as following :
    query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= Date() ;"; ---------------------
    Hope this helps.
    Thanks

  • Function Modules for Data and Time

    Hi all,
              I need 2 function modules for date and time. when we pass current data(sy-datum) and current time (sy-uzeit) into function modules, shoud get date in <b>dd/mm/yyyy or dd.mm.yyyy</b> and time in<b> HH:MM:SS</b> formats.
    Thanks in advance

    Hi Ranjith,
    i think this will b usefull for you..
    SAP Bar Chart Function Modules and what they are used for
    Function module
    Used for
    BARC_GRAPHIC_PBO
    Starting bar chart at PBO time, using a graphic profile (parameter PROFILE)
    BARC_GRAPHIC_PAI
    Analyzing data returned by the graphic
    BARC_SET_TIME_AXIS
    Setting start and end of time axis
    BARC_SET_OPTIONS
    Setting options
    BARC_ADD_CHART
    Creating a chart
    BARC_SET_CHART_ATTRIB
    Setting chart attributes
    BARC_ADD_SECTION
    Creating a section on the time axis
    BARC_SET_SECTION_ATTRIB
    Setting section attributes
    BARC_ADD_RIBBON
    Adding a ribbon to the time axis
    BARC_SET_RIBBON_ATTRIB
    Setting attributes for ribbons in the chart
    BARC_ADD_GRID
    Adding a time grid
    BARC_SET_GRID_ATTRIB
    Setting grid attributes
    BARC_ADD_LAYER
    Adding a layer (graphic elements)
    BARC_SET_LAYER_ATTRIB
    Setting layer attributes
    BARC_ADD_LINE
    Adding a line
    BARC_ADD_CALENDAR
    Creating a calendar
    BARC_SET_CALENDAR_ATTRIB
    Setting attributes for a calendar
    BARC_ADD_TIME_PROFILE
    Creating time profiles
    BARC_SET_TIME_PROFILE_ATTRIB
    Setting attributes for time profile
    BARC_ADD_INTERVAL
    Adding a time interval
    BARC_SET_INTERVAL_ATTRIB
    Setting time interval attributes
    BARC_ADD_TIME_OBJECT
    Creating a time object
    BARC_CONVERT_DATE
    Creating a date string in bar chart format
    BARC_REVERT_DATE
    Converting a date string in bar chart format to date and time
    BARC_ADD_DATELINE
    Creating a date line
    BARC_SET_DATELINE_ATTRIB
    Setting dateline attributes
    BARC_GET_PROFILE_CONTENTS
    Obtaining profile contents for customizing a chart
    BARC_GET_COLUMN_WIDTH
    Selecting new column width
    BARC_SET_COLUMN_WIDTH
    Setting the column width
    BARC_GET_TEXTINDEX
    Obtaining the text index of a field
    BARC_SET_LABELS
    Positioning the chart display
    BARC_SET_COLUMN_ATTRIB
    Setting column attributes
    BARC_SET_ROW_ATTRIB
    Setting row attributes
    BARC_SET_ROW_HEIGHT
    Setting the line height
    BARC_SET_MAXCHARTS
    Setting the maximum number of charts sent
    <b>If its usefull reward points
    </b>

  • Schedule background Job Programatically at specified date and time

    Hi Everybody,
    how can i schedule a job  in background programatically for a spefic date and time ?
    Thanks and Regards
    srikanta

    Hi Chandrasekhar,
    my requirement is :
    in selection screen there will be two run mode :
    1) Run in Foreground
    2) Run in Background
    If user selects  ' Run in Background ' option , a block will open where user can give
    job schedule date  and
    job schedule time.
    Based on this date and time program will be scheduled in background.
    I have used like this :
    CALL FUNCTION 'JOB_OPEN'
          EXPORTING
            jobname                = v_jname
            SDLSTRTDT              = p_date
            SDLSTRTTM              = p_time
          IMPORTING
            JOBCOUNT               = v_jcnt
         EXCEPTIONS
           CANT_CREATE_JOB        = 1
           INVALID_JOB_DATA       = 2
           JOBNAME_MISSING        = 3
           OTHERS                 = 4.
    where v_jname is jobname
              v_jcnt   is jobcount
              p_date is  schedule date ( taken screen value)
             p_time is  schedule time ( taken screen value)
    but the job is sxcheduling immediately
    Give suggestion.
    Thanks in advance.
    Srikanta

  • How can i change date and time after importing a file

    hello
    i'm importing AVI files first in iMovie because Final doesn't support (other question i put in) but when i see the scenes form 1993 they have the date 2004.
    i believe 2004 is the date i put them on the computer.
    Now i looked in the help files Final Cut Pro but cant find anything to adjust the date and time.
    it works well in iMovie using the help files:
    Right-click the clip you wish to edit and click Adjust Clip Date and Time from the menu that appears. Or click on Archive and than adjust date and time
    But as i said i cant import the files in FCP have to import them to  iMovie files adjust the date and than import to Final Cut Pro but than de changes i made to the date and time  are gone and in FCP 2004 is again the date of the file!!!
    Question how can i Change in Final Cut Pro the date and time in a same way as iMovie does?
    Jemajoro

    OK, I think I understand what you are saying but it still does not look like it is doing it as you describe.
    Here is another screen shot.
    Note that all clips in "2007 August" event have the date of Aug x, 2007.
    Yet, the event "2007 August" still shows up under the 2012 "folder" (is that the right terminology?).
    The newest clip in this event is Aug 31, 2007 so shouldn't it be categorized as 2007 and not 2012?
    I think you know this but I am using the following feature:
    Go to the sprocket icon under the events.
    Select "Group events by date" and then by "group events by year and month"
    Thanks again for all the help

Maybe you are looking for

  • Error opening external DTD 'Segnatura.dtd' using dbms_xmlsave.insertXML

    I've been trying to insert a document in a table. All works fine if the xml doesn't contains the doctype element! If I add the row <!DOCTYPE Segnatura SYSTEM "Segnatura.dtd"> to my xml I get the error: oracle.xml.sql.OracleXMLSQLException: Error open

  • Posting Customer Invoice using FB70

    Hi Experts, While posting customer invoice (FB70) for the customer having withholding tax information defined, I am able to simulate the transaction successfully but not able to post it.I can see the TDS transaction executed.But, the post icon symbol

  • Create Temporary Tables

    Hi, there. Can anybody tell me what's the syntax for the SQL statements to create temporary tables? I'm developing a shopping cart, and at the end of every purchase (checkout) I want to organize the items of the Session Bean Hash Table that contains

  • Implementing the HIRE act in SAP US Payroll

    Hi Experts, Since the new HIRE Act is a regulatory requirement, customers are demanding patch from SAP 's end to implement in the SAP HR system. Is anyone aware if SAP has already delivered a patch update relevant to this? Regards, Somdeb.

  • Changing Metadata Deletes Artwork-Why?!

    So, I'm 40, and I like whole albums. Spotify and Pandora are not things that work with me. And I'm not jumping into this cloud thing because I end up in areas with no service. I want my music with me, on my own terms, because I own it. It's mine. I'm