Rounding Time to nearest 30 minutes

Good day,
I'm looking for a way to round the time portion of a date value. My query needs to return the time of day, rounded to the nearest 30 minutes - top of the hour or bottom of the hour.
If sysdate is: 12/28/2009 11:08:19 AM
I need to see: 12/28/2009 11:00:00 AM
If sysdate returns: 12/28/2009 11:18:19 AM
I need to see: 12/28/2009 11:30:00 AM
Any help is appreciated.
Regards,
Gary F.

Aketi Jyuuzou wrote:
I like case expression B-)Me too, but I like then simple B-) :
with dates as ( -- generating sample data
select to_date('12/28/2009 11:08:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
select to_date('12/28/2009 11:18:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
select to_date('12/28/2009 11:38:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
select to_date('12/28/2009 11:48:19', 'mm/dd/yyyy hh:mi:ss') from dual)
select dt,
case when to_char(dt,'mi') >= '45'
     then trunc(dt,'hh') + interVal '60' minute
     when to_char(dt,'mi') >= '15'
     then trunc(dt,'hh') + interVal '30' minute
     else trunc(dt,'hh')
     end as new
  from dates
DT                  NEW
2009-12-28 11:08:19 2009-12-28 11:00:00
2009-12-28 11:18:19 2009-12-28 11:30:00
2009-12-28 11:38:19 2009-12-28 11:30:00
2009-12-28 11:48:19 2009-12-28 12:00:00
SQL> SY.

Similar Messages

  • Rounding time to nearest hourly quarter

    I have several records like
    2/19/2010 1:25:46.000000 PM
    2/19/2010 1:40:46.000000 PM
    2/19/2010 1:55:46.000000 PM
    2/19/2010 2:10:46.000000 PM
    I want to round them off to the nearest quarter like
    2/19/2010 1:30:00.000000 PM
    2/19/2010 1:45:00.000000 PM
    2/19/2010 2:00:00.000000 PM
    2/19/2010 2:15:00.000000 PM
    Any ideas how I would do that? a trunc(col,'mi) only lets me round it to the minute..
    Note that records are not necessarily in the 5 minute interval difference it can also be 7 minute difference or 4 minute difference from the nearest quarter...
    so I can also have records like
    SysUpTime     2/19/2010 10:31:00 PM
    SysUpTime     2/19/2010 10:57:00 PM
    SysUpTime     2/19/2010 11:31:00 PM
    etc.
    Edited by: zebango on Mar 9, 2010 4:16 PM

    Solomon Yakobson wrote:
    But OP asked for "*Rounding* time to nearest hourly quarter". Same applies to Aketi's solution which, BTW, which always bumps it up to next 5 min.In which case, just substitute "Round" for "Floor"!
    Although thinking about it, you'd probably want to add seconds into the mix:
    with table_x as (select to_timestamp('11/03/2010 11:45:39', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 11:52:29', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 11:52:30', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 11:52:31', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 12:00:01', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 12:07:29', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 12:07:31', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 13:22:10', 'dd/mm/yyyy hh24:mi:ss') t from dual union all
                     select to_timestamp('11/03/2010 13:22:40', 'dd/mm/yyyy hh24:mi:ss') t from dual)
    select t,
           trunc(t, 'hh') + ROUND((to_char(t, 'mi') + (to_char(t, 'ss')/60))/15)*15/1440 nearest_15_min
    from   table_x
    T                                NEAREST_15_MIN      
    11/03/2010 11:45:39.000000       11/03/2010 11:45:00 
    11/03/2010 11:52:29.000000       11/03/2010 11:45:00 
    11/03/2010 11:52:30.000000       11/03/2010 12:00:00 
    11/03/2010 11:52:31.000000       11/03/2010 12:00:00 
    11/03/2010 12:00:01.000000       11/03/2010 12:00:00 
    11/03/2010 12:07:29.000000       11/03/2010 12:00:00 
    11/03/2010 12:07:31.000000       11/03/2010 12:15:00 
    11/03/2010 13:22:10.000000       11/03/2010 13:15:00 
    11/03/2010 13:22:40.000000       11/03/2010 13:30:00 

  • My mac book pro will not fully boot up. I have the grey background with the apple sign and the timer going round...but 20 minutes later still no desktop

    My mac book pro will not fully boot up. I have the grey background with the apple sign and the timer going round...but 20 minutes later still no desktop

    You could try doing a hard shut down (holding the power button or yanking the battery) and then doing a safe boot by holding the shift key at startup:
    http://support.apple.com/kb/HT1455
    Also, not sure if this applies in your case, but I've had that happen when there's a USB drive inserted either in the computer or a connected external keyboard.  I did a hard shut down, removed the drive and it went through a normal start up. 

  • Rounding time field to nearest half hour

    Post Author: fiscyn
    CA Forum: Formula
    Is there a way to round a time field?
    For example,  if a time field is from 9:01 to 9:14  I want it to round back to 9:00;  
    9:15 to 9:29  or 9:31 to 9:44   I want either option to round to 9:30
    and 9:45 to 9:59 I want to round to 10:00.
      I want to keep the original time and have the rounded time listed next to it.    Also I want this for a 24 hour clock, military time.  Don't know if that makes a difference.
    Any help is appreciated.
    Thanks.

    Post Author: fiscyn
    CA Forum: Formula
    I'm slowly getting this to work.    Just a couple problems,  minor I hope.
    I used the CTime function and used the rounding formulas for minutes and hours as you suggested.  It works great.   But the results for the hours come out as 12.00  and the minutes as 30.00 or 0.00.   How do I drop the decimals?   I tried the totext, 0 function,  but the numbers don't line up correctly.   If the hour is 9.00,  it drops the zero place holder.   So if 9 and 10 are lined up,  the 9 is above the 1 instead of the 0.  
      It works fine for the minutes except I end up with 0 instead of 00.   Any suggestions?
    I greatly appreciate the help so far.   Thank you.

  • Data usage rounded up to nearest GB in Bill summary; Cannot download details as spreadsheet

    Two problems:
    1. Bill summary misrepresents data usage, rounding up to the nearest GB, for one of our 4 lines.
    2. Data detail "download to spreadsheet" does not work.
    My account has 4 lines. I have an old Family Share plan (no longer available) for 700 minutes; a "feature" for unlimited text; and individual data plans for each of the 4 lines. My daughter has a 2 GB data plan.
    Latest Verizon Wireless bill says my daughter used 1.0000000 GB of data. She didn't think so. I logged in to Verizon, went to "View Bill". then for the Bill Period: May 29, 2014 - June 28, 2014, I selected "Details for" > "DATA". I see all the usage by date and time; I can adjust the display from default "KB" to "MB". Then I clicked the link "Download to SpreadSheet ".
    Unfortunately, I get a file with only one line, just the headers, no data:
    "Date"    "Time"    "Usage Type"    "Description"    "Minutes"    "Application Price"    "Total"
    As a workaround, I can select and copy the data on the web page, then paste it into a spreadsheet program. I added a "sum()" formula and found that she used only 325 MB, not 2 GB.

    Does the bill say she used 1 GB or 2 GB? You had mentioned them both.
    As far as the usage, it's not too say she literally used that much but to say that she used that much or less. It may not matter since she has the 2 GB/$30 which means that you would be billed the same way either way.
    Your inability to download the spreadsheet may be due to an issue with your browser.

  • Rounding off to nearest whole number without condition

    hi,
    i want to round a real number to an integer value,,wihout any conditions like
    10.01 should be 11
    10.1 should be 11 and like that
    is it posible to do it?
    thanks in advance.
    amit

    It doesn't look like you are trying to round to the nearest whole number here. It looks like you are trying to find the smallest integer value that is greater than or equal to the real number. If so, you would want to use the CEIL function (i.e.
      1  SELECT CEIL(10.01)
      2*   FROM dual
    SCOTT @ hp92 Local> /
    CEIL(10.01)
             11Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Deadline in a period of time less than a minute

    Hi there,
    we're implementing a BPM where there is a time-dependent loop. We used the deadline branch in a block step, that setp is ok, but there is a problem.
    We need a maximum deadline about half a minute, but the deadline unit parameter won't accept seconds, just minutes or longer time units.
    We had thought of using a fork step where the 2nd branch would be nothing but a transformation step and a control step. The transformation step would countain a mapping where I could implement a java code with a wait method of a determined delay (this is needed because the wait step also only suports time units up to minutes). When this wait was completed, the control step would throw a timeout exception and terminate the block (thus the loop).
    But there are some gaps in this approach:
    1. the process start trigger is located in the receiver step, which is inside the loop, in the first branch of the fork. How to start the 2nd branch of the fork (the wait branch)?
    I had thought of creating a new message interface of a simple datatype to use as a trigger for the wait branch. After the receiver in the main loop of the 1st branch of the fork, I'd put a send step which would send a message of this type to the BPM itself. Then, I'd put a receiver step in the 2nd branch of the fork before the transformation step, just to start the branch. To guarantee that only one start message would be sent, the send block inside the main loop could be put into a switch step, and I could create a flag as simple type container which would be flagged false (hence not running the send step anymore) once the trigger send step ran for the first time. Would this work?
    2. Is it really possible to use the mapping in this sense?
    Is there a less drastic way of performing this wait step with seconds unit?
    Thanks in advance.

    > Go to properties of the Fork step and make the
    > necessary branches to be 2.
    You make like this, and let it execute 2 Fork Branches, but before executing the steps inside the Fork Branch, you can use Switch condition, so that is some data/id exists then only go to the fork branch, otehrwise don't do anything.
    Did u see the option of the Message Based loop. If not it will help you on this entire scenario. But you need to have one stop message from the Source, stating that , this is the last message.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/0e/56373f7853494fe10000000a114084/frameset.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/08/16163ff8519a06e10000000a114084/frameset.htm
    Hope this helps,
    Regards,
    Moorthy

  • RAS failed to start - It has stopped 5 time(s) in 60 Minutes

    Hi Guys - I am also having same problem with BOXI 3.1 SP2, the RAS not getting started. I did clear all the pending reports restarted BO server couple of times, however the RAS still not getting started.
    When I try ti start it maually from BO it gives the above error that "RAS failed to start - It has stopped 5 time(s) in 60 Minutes"
    In the WIReportServer log I see following errr -
    ceserver.cpp:1066: TraceLog message 1
    2011/05/09 16:26:56.802|>>|E| |25457| 45| |||||||||||||||**ERROR:ceserver:invalid entry General\Directories\Config in registry http://ceserver.cpp;1066
    Please note this server was running very fine till today, from last 3-4 months. No changes being made to server or configuration. Any suggestions, help much appriciated.
    Many Thanks.

    We are running on Solaris 10 and my issues is about crystal reports.
    Did try restart by clearing all the processes howeve no difference to the RAS same error.
    Appriciate any helpful direction..
    Thanks..!!

  • How do I convert time from hours and minutes to decimal time

    I am making a spread sheet a work for payroll. I need to make a formula that converts the time from hours and minutes to decimal time. Please help

    Hi Taryn,
    I can't see much from the photo, but I assume your formula is similar to the one I've used below:
    The same formula is used in F4 and F6, and both return the same result (shown in F4).
    F4 was left on "automatic" cell format, and the column widened to accomodate the repeating decimal to the point where Numbers would begin displaying zeros.
    F6 was formatted as shown in the Cell Inspector to show only two decimal places.
    Neither of these is an "exact" decimal, as it is not possible to use a decimal fraction to "exactly" represent 1/6 (or 10/60).
    The likely reasons for yours showing a whole number of hours is a difference between your formula and the one shown in the example here, or a difference in the number of decimal places set in the cell's format.
    Regards,
    Barry
    PS: To take a screen shot:
    Place the mouse pointer at the top left corner of the area you want to nclude in the shot.
    Press shift-command-4.
    Use the mouse to drag a selection rectangle contining the part of the screen you want to include.
    Release the mouse button. (You'll hear the sound of a camera shutter 'snapping' the picture.)
    The screen shot will be saved to your desktop with the name 'screen shot' followed by the date and time.
    The image may be posted to the discussion using the same steps you used to post the photo above.
    B.

  • I'm installing 10.7 and it will not finish.  The time goes into negative minutes.

    I'm installing 10.7 and it will not finish.  The time goes into negative minutes.  It is on a 2 year old 13.3 Macbook Pro. Had hopes of wiping the hard drive durring the install. Any ideas?

    Ok, so after like 4 days of going through all these different issues, I figured out that several programs weren't downloading, and it was an issue with my wireless connectivity messing up the digital signatures, so if you plug in your comp to the modem and delete your temp files, it should start to work!

  • Winter time - clock always 20 minutes off

    Hi,
    Twice a year, the time changes here, and in october the time changes to winter time. Apparently my Archlinux does that automatically, how nice of it.
    However, EVERY time, so I go through this shit twice a year, the week or two weeks after such a time change, my computer is always +/- 20 minutes off when I reboot it.
    For example:
    Today I booted up my computer at 7:45PM, and the time it displayed was 7:21PM.
    You see? The error is not one hour, it is something near 20 minutes.
    So I use "date -s" to set it to the actual date. And for the coming week or so I'll have to do that every time after I reboot again, because tomorrow when I reboot, the day after that, and so on, it'll always do this again. And after a week or two it'll suddenly stop happening.
    I'd like to ask two things:
    -How do I fix this, I find this very annoying and NEVER want to see this again.
    -Why does it happen? Why 20 minutes? What kind of process could be programmed to do something confusing to the clock involving a time of around 20 minutes?? It could be Archlinux itself, or KDE 3.5, or something else, I haven't got a clue.
    Please help, I'm tired of this shit twice a year.
    Windows doesn't do this by the way, so don't blame my hardware.

    It was the hwclock. So it kind of was my hardware to blame anyway.
    I did "hwclock --systohc" and hopefully that fixed it forever.
    Sorry if my post sounded a bit frustrated, it's just because it was such an annoying problem.
    It still remains a problem with weird behaviour: on a day where the time changes, it does it perfectly when booting that morning. The next +/- 14 days, it's skewed every morning. Then it's stabilized again.
    Thanks for the help!
    Last edited by aardwolf (2010-11-01 19:18:21)

  • Datepiker rounding seconds to nearest minute in presentation?

    Hi all,
    I have a presentation with a display-only, non-editable datepiker, that references an object variable of type Time.
    The variable contains a full timestamp with date and time down to microseconds; however when the time gets displayed in my presentation, the seconds are always rounded to 00.
    Has anyone encountered this or know how to deal with it?
    Thanks!
    B

    Hi all,
    I have a presentation with a display-only, non-editable datepiker, that references an object variable of type Time.
    The variable contains a full timestamp with date and time down to microseconds; however when the time gets displayed in my presentation, the seconds are always rounded to 00.
    Has anyone encountered this or know how to deal with it?
    Thanks!
    B

  • Graph plot in labview to get time in seconds or minutes in X axis starting from 0.

    How can we obtain time starting from 0 seconds or 0 minutes on X axis in a chart and XY graph in labview.When I plot it is showing the system time on   X axis.I would prefer the time to start from 0 ( seconds) , rather than system time.Please reply.

    I have NI cDAQ 9174 chasis and NI 9211 and NI 9207 for thermocouple (NI 9211) and current (NI 9207).Can I acquire all three data inputs within a single DAQ Assistant express vi.Because I tried to access all 3 in one DAQ Assisstant , but it was not accepting it.So I had to place one DAQ Assisstant for thermocouple readings and another for current.For reference I have attached my labview diagram.
    Attachments:
    rktr3.vi ‏218 KB

  • I want to overlay elapsed time for 30 hour time lapse onto 30 minute video.

    Title says it all.  I have 92k pictures that I've put into an ~30 minute time lapse video.  The pictures came from about 30 hours of recording.  I would like to add a clock to show the time on to the video.  I have sequences broken up by hours of the day, so I could create one hour segments very easily.
    I've tried playing around with the timecode filter, but it doesn't do what I want it to (or I can't figure how to make it do what I want it to do).
    Thanks for the help.

    There isn't a built in clock effect in PrPro... timecode is the closest to it but probably won't work for what you want. After Effects may have one, but I'm not sure. There are probably some third party ones but I don't know of any off hand. Otherwise you may have to build and animate it yourself using titles or something like that. Again AE may help with that but I'm not certain. The time lapse part should be pretty easy. You can import them as image sequences if they're sequentially named, or else import them with a 1 sec default duration and add them to an appropriately sized sequence using automate to sequence or just by dragging and dropping.

  • Help: ResulSet.getDate(int col) rounds time to 12:00AM

    Using Microsoft SQL Server 7, I execute the following code:
    CREATE TABLE Test (RegDate DATETIME, SmallDate SMALLDATETIME)
    INSERT INTO Test (RegDate, SmallDate) VALUES ('1/1/2000 5:37 AM', '1/1/2000 5:37 AM')
    SELECT * FROM TestThis is the output that I get back:RegDate                     SmallDate                  
    2000-01-01 05:37:00.000     2000-01-01 05:37:00Ok, it looks good so far... now let me query this table with JDBC://just a snippet... I already have a connection, and a statement (stmt)
    SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy h:mm:ss a");
    ResultSet rs = stmt.executeQuery("SELECT * FROM Test");
    while(rs.next()) {
        System.out.println("RegDate is " + format.format(rs.getDate(1)));
        System.out.println("SmallDate is " + format.format(rs.getDate(2)));
    }The output from the java code is:RegDate is 1/1/2000 12:00 AM
    SmallDate is 1/1/2000 12:00 AMThe month, day and year are correct but the hours and minutes are 12:00 AM. How can I get the hours and minutes?
    Thanks,
    jay

    Okay, I did some reading and I learned that java.sql.Date will always show 12:00 AM (aka zero). There is a class called java.sql.Time which should take care of the time.
    I still don't know how to get the Date and time from a ResultSet though. I can call ResultSet.getDate(int col) or ResultSet.getTime(int col) but not both (after getting a column's value, subsequent calls return null). I even tried getting raw data and parsing it via ResultSet.getBytes() and ResutSet.getBinaryStream()... common sense tells me that there's got to be a cleaner, simpler way to do this. Surely I'm not the first person who wanted to read the date and time from a SQLServer DATETIME column!
    thanks again

Maybe you are looking for

  • Song not the same as the title

    My itunes has experienced more than once where the song title is NOT the song being played.  No one but me has access to my itunes so that the info has been changed.  I am certain I loaded this one particular song one.  Went to play it and behold, it

  • I am not able to attach my Robohelp 10 license key to my Adobe account.  It tells me it is an invalid license key.

    Several times now, I have chosen the option to activate the product and proceed to login with my Adobe account and enter the license key and it registers the product, but after a couple days it will show me the start screen again indicating I'm in a

  • Compiling the basic invoke example

    Hello everybody! I need your help :p Sorry for my english, I'm french... I just want to call java method from a c++ program. I've read that JNI do that, so I tryed to compile the basic example "invoke" (http://java.sun.com/docs/books/jni/html/invoke.

  • Trouble viewing QT Trailers with new QT version?

    Hey there, I'm having trouble viewing QT trailers, especially HD trailers, that used to download and play perfectly from Safari. Is anyone else having this new problem ? thanks, tnixer

  • Canon Vixia, Log & Transfer, .MTS help!

    I have a Canon Vixia. I used to be able to use Log and Transfer to ingest the footage into my Final Cut Pro 7, but all of a sudden it doesn't work. My macbook doesn't even recognize the MTS files, they are greyed out when I use the "Add Volume" butto