Calcuate hours

Hi all,
I want to calculate the hour from the date
If the date/time passed occurs at or before 5pm 'today' means (17 hours)then
-return 0, otherwise return 1
Please can you help me to write a query for this.

HI,
SQL> with a as ( select
  2  to_timestamp('12/02/2011 15:25:30','dd/mm/yyyy hh24:mi:ss') da from dual)
  3  select case
  4          when extract(HOUR from da) < 17 then 0
  5          else 1
  6          end transf
  7  from a;
    TRANSF
         0
SQL> with a as ( select
  2  to_timestamp('12/02/2011 18:25:30','dd/mm/yyyy hh24:mi:ss') da from dual)
  3  select case
  4          when extract(HOUR from da) < 17 then 0
  5          else 1
  6          end transf
  7  from a;
    TRANSF
         1
SQL>

Similar Messages

  • Query help: using ytd hours earned to calcuate hours accrued each month

    We’d like to calculate the hours accrued per month for each employee on both sick and vacation leaves between January and June. (EmployeeID 002 just started in April).
    We only know the year-to-date hours earned for each employee and hours accrued each month could vary. We can use the lag function to calculate the hours earned for every other month, except for the beginning month (please see the column named monthly_earned_using_lag_function, where the monthly_earned data are missing for 001 on January and for 002 on April. Is there any way that we can include the hours accrued for the beginning month? The final result we expect to achieve can be seen from the column named monthly_earned_with_correct_result.
    Bunched of thanks to your advice in advance.
    The sql we used looks like this:
    Select id, plan, month, ytd_hours_earned, ytd_hours_earned –lag( ytd_hours_earned) over (partition by id, plan order by id, plan, month) as monthly_earned_using_lag_function from leaves
    id   plan         month     ytd_hours_earned       monthly_earned_using_lag_function       monthly_earned_with_correct_result
    001     sick             01             8                                                                                          8
    001     sick             02             16                         8                                                             8
    001     sick             03             22.5                          6.5                                                          6.5
    001     sick             04             28                        5.5                                                          5.5
    001     sick             05             34                             8                                                             8
    001     sick             06             43                             9                                                             9
    001     vacation     01             14                                                                                      14
    001     vacation     02             28                           14                                                           14
    001     vacation     03             42                           14                                                           14
    001     vacation     04             56                           14                                                           14
    001     vacation     05             70.5                       14.5                                                         14.5
    001     vacation     06             85.5                   15                                                            15
    002     sick             04             8                                                                                                   8
    002     sick             05             16                             8                                                             8
    002     sick             06             24                             8                                                             8
    002     vacation     04             10                                                                                      10
    002     vacation     05             20                           10                                                           10
    002     vacation     06             30                           10                                                           10

    Hi,
    You can use LAG for that. The optional 3rd argument to LAG is the value to return in case there is no prior row.
    SELECT    id
    ,       plan
    ,       month
    ,       ytd_hours_earned
    ,       ytd_hours_earned – LAG (ytd_hours_earned)
                                     OVER ( PARTITION BY  id
                                    ,           plan
                                    ORDER BY          month
                                  ) AS monthly_earned_using_lag
    ,       ytd_hours_earned – LAG (ytd_hours_earned, 1, 0)                -- ***** NOTE 3rd argument *****
                                     OVER ( PARTITION BY  id
                                    ,           plan
                                    ORDER BY          month
                                  ) AS monthly_earned_correct
    FROM      leaves
    ORDER BY  id
    ,            plan
    ,       month
    ;By the way, there's no point in ORDERing BY an expression that's in the PARTITION BY clause. If you say "PARTTIION BY id", then two rows will be compared with each other only if they have the same id, so they will always tie when you ORDER BY id.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Calcuate Hours: Minutes:Seconds between two dates excluding Weekends

    Hello All,
    @StartDate = '2014-06-21 13:37:30:037'
    @EndDate = GetDate()
    I want to find out Hours:Minutes:Seconds between the above dates EXCLUDING WEEKENDS.
    Please help.
    ReportingServices

    Hi,
    Give this a try:
    DECLARE @StartDate DATETIME = '2014-06-21 13:37:30:037'
    DECLARE @EndDate DATETIME = GETDATE()
    DECLARE @Base INT = 86400 -- ie Seconds in a days
    ;WITH cteCalculation AS (
    SELECT ((
    (DATEDIFF(dd, @StartDate, @EndDate) + 1)
    -(DATEDIFF(wk, @StartDate, @EndDate) * 2)
    -(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
    -(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)
    ) * @Base)
    -(CASE WHEN DATENAME(dw, @StartDate) NOT IN ('Saturday', 'Sunday') THEN DATEPART(hh, @StartDate) * 3600 + DATEPART(mi, @StartDate) * 60 + DATEPART(ss, @StartDate) ELSE 0 END)
    -(CASE WHEN DATENAME(dw, @EndDate) NOT IN ('Saturday', 'Sunday') THEN @Base - (DATEPART(hh, @EndDate) * 3600 + DATEPART(mi, @EndDate) * 60 + DATEPART(ss, @EndDate)) ELSE 0 END)
    AS DiffInSec
    SELECT @StartDate
    ,@EndDate
    ,CAST(DiffInSec / 3600 AS VARCHAR(10)) + ':' +
    RIGHT('0' + CAST((DiffInSec % 3600) / 60 AS VARCHAR(2)), 2) + ':' +
    RIGHT('0' + CAST((DiffInSec % 3600 % 60) AS VARCHAR(2)), 2)
    FROM cteCalculation
    Feel free to modify to suit your needs!
    Hope this helps.
    ~J.

  • Calculating hours in numerical formats between 2 business days, calculated column

    Hi there,
    I need to calculate how many hours are between 2 days only including business days, outputting in numerical format (ex. 7.3). 
    I've been using this formula to output how many weekdays are between 2 days.
    =IF(AND((WEEKDAY(CompletedTimeStamp,2))<(WEEKDAY(,2)),((WEEKDAY(Created,2))-(WEEKDAY(CompletedTimeStamp,2)))>1),(((DATEDIF(Created,CompletedTimeStamp,"D")+1))-(FLOOR((DATEDIF(Created,CompletedTimeStamp,"D")+1)/7,1)*2)-2),(((DATEDIF(Created,CompletedTimeStamp,"D")+1))-(FLOOR((DATEDIF(Created,CompletedTimeStamp,"D")+1)/7,1)*2)))
    The problem with this is if the 2 dates are on the same day, it outputs "1". I need it to output the amount of hours then / by 24 to give me ".7"  instead.
    Is there anything I can do to convert this current formula to give me hours instead of days?
    Thanks,
    Terence

    The DATEDIF is rounding to the nearest day.
    Try this:
    =IF(AND((WEEKDAY(CompletedTimeStamp,2))<(WEEKDAY(,2)),((WEEKDAY(Created,2))-(WEEKDAY(CompletedTimeStamp,2)))>1),(((CompletedTimeStamp-Created+1))-(FLOOR((CompletedTimeStamp-Created+1)/7,1)*2)-2),(((CompletedTimeStamp-Created+1))-(FLOOR((CompletedTimeStamp-Created+1)/7,1)*2)))
    -1
    Then above will return fractions of days, i.e.  5.5 days. Multiply this by 24 for hours.
    I think there is a extra "+1" in the above example somewhere, so I added a minus 1 to get back the correct value.
    Hi.. Mike.. I am trying to use this calcuation.. its renndering "time being used 3.3".. I need it to calcuate a work day as 8 hrs  so if
    Start Date= 9/12/2014 9:00am
    End Date= 9/16/2014 5:00 pm
    should be 3 (8 hr work days)  any way I can fix this?
    Thanks in advance for your help.
    Mike Smith TechTrainingNotes.blogspot.com

  • Machine Hour Rate

    Dear All,
    In our shopping flour we have a one Mechine of 10,00,000/-, every day we have so many project are working on that Mechine.
    Here my point is how we can calculate the Mechaine Hour Rate.
    for EX:
    If we have taken KP06
    Cost Element : Mechine Hour Rate
    Cost Center :  Department A
    then _I have to maintain the 10,00,000/- _   Is it correct?
    then in KP26
    Cost Center : Department A
    Work Center : Work Center A
    if i Execute, then what can i Menchition : Life span of the Mechaine Hours Is it correct?
    If both are correct statements then i will calcuate the KSPI Automatic Calculation.
    Regards

    Closed

  • MBP 15'' 2011 battery lasts only 3 hours!

    Hi
    I bought MBP 2011 15 inch last week and received it on Monday.
    My configs are
    Model Name:          MacBook Pro
      Model Identifier:          MacBookPro8,2
      Processor Name:          Intel Core i7
      Processor Speed:          2.2 GHz
      Number of Processors:          1
      Total Number of Cores:          4
      L2 Cache (per Core):          256 KB
      L3 Cache:          6 MB
      Memory:          4 GB
    and I also upgraded to high resolution.
    So far, I'm pretty much enjoying my new MBP
    But I have one main concern with my new laptop's battery time.
    The battry time is really really short!
    When I first turned it on, it took 3 hours to drain the battery. (starting from 98% or so)
    And I did calibration thing so that the battery runs more "efficiently"
    Of course, I didn't expect that calibration would make the battery last longer, but no matter what,
    I only get 3 hours of battery life and I'm not even doing something that would drain my battery fast.
    I just do simple web surfing and word documenting on about 30-40% brightness (or even lower sometimes)
    And I get only 3 hours of bettery time.
    So is this because my MBP has four i7 cores or or what?
    Previous MBP 15'' models seem to last at least around 5 hrs doing exactly same thing.
    And considering that I have been using my MBP only for 5 days or so, I'm worried that the battery life will become even less!
    Maybe like 2 hrs?
    Is this a particular issue with my laptop, that I can return and exchange to new model or get fixed without fees?
    Or is it just built this way that all the MBP 2011 15'' models have this kind of short battery life?

    OMG turning off the Bluetooth just gave me like extra 3 hours of battey time! (6 hrs total)
    I didn't even know it was turned on in the first place because I never touched it.
    I guess bluetooth is on as a default setting.
    Thank you so much for advice.
    I feel so stupid, but please be understanding since it's actually my first MacBook.
    But I'm really glad to find out that I was wasting battery with bluetooth on, and now I can get better battery time.
    Thanks once again!

  • Yesterday, as today's deadline for filing tax returns approached, I was paralyzed by the inability to create new IRS PDF forms and to retrieve archived ones from a year ago. My computer went crazy. 24 hours later, I am still paralyzed. Can you help?

    My computer went crazy yesterday on two occasions involving PDF documents. One dealt with attachments to an email from a bona fide corporation. The other dealt with IRS PDF forms & schedules needed for today's submission.
    As both dealt with PDF and had nothing else in common, I suspected my PC had a virus. When I asked a local store technician, he agreed. I turned to Norton, which protects my PC from viruses, and after a few hours of really thorough searching, the computer was found to have no viruses.
    Before describing what I call "crazy" computer behavior, you need to know that I have long had IE8 as my default browser but a few weeks ago switched to Mozilla Firefox because IE8 had beome incompatible with some websites from which I get information.
    When I received the email from AT&T email service and clicked the first of four icons representing attachments, there was figuratively an explosion on my monitor: a series of new tabs, each called New Tab, burst onto the monitor--but no text or picture. The new tabs appeared faster than I coul kill them. I finally decided just to shut down the computer, hoping they would not reappear when I restarted. I was wrong. After 2 repeats, I decided to forget about the attachments and asked the sender to send them to me by regular mail.
    That was no solution for my IRS PDFs. I wanted to complete filling in the various forms and schedules that I had begun months ago so that I could mail them today to the IRS (without having to copy them all in ink). When I tried to open the first one, BOOM. The same thing happened: the blizzard of New Tabs atop blank pages; my IRS form or schedule did not show up. Did the same shutdown/restart routine with the same results.
    When I looked at the list of current forms that had to be completed, I noticed something very strange: the icons that began the listing of the documents' names were replaced one by one by Mozilla icons. When I moused over them, they said Firefox HTML. Why?
    Starting the day today, I had the same experience. What's more, when I started to retrieve 2012 IRS PDFs from a year ago, the same New Tab tabs appeared and had to be killed, and Mozilla icons replaced whatever icon was there before.
    Assuming that the problem arose with Adobe Reader's reading of the PDFs, I contacted Adobe but got no helpful phone number because PDFs are a free service and was directed to use this Forum to get help.
    What do I have to do to (a) read and use PDFs in the normal way and (b) remove the Mozilla icon from those that have appeared on icon documents. If Mozilla is the source of the problem, shall I go back to IE8? (In my 80s, I want eventually to replace my old computer but for the time being I must continue using it. It will not take an IE9. Anther possible default browser would be Google Chrome, but I have unfavorable impressions of it because of its intrusiveness, loading my PC with stuff I do not need.
    Can you help?

    The problem is absolutely not Reader. The problem is that FireFox has stepped in front of Reader and handles all the PDF stuff - wrongly in your case. FireFox is DESIGNED to take over PDF files. But it is not capable of doing IRS forms!
    To start with go back to IE for these forms. When you save them to disk DO NOT DOUBLE CLICK ON THEM until this is fixed. Just open the in the normal way - start Adobe Reader and use Open from the File menu.

  • Open and close application at some hour.

    Is it possible that Automator opens one or more applications at, for example, 3 in the morning and close it/them 4 hours later?
    If possible, how can I do it?
    Thanks.

    What do you do if the application (Azureus) does not appear to be scriptable?
    No AppleScript library for it appears in AppleScript Editor. It is a Java App. When I attempted to run the script it just times out for ever waiting for a reply from Azureus. Azureus itself sets up the spinning beachball of death.
    I was hoping to simply be able to record closing the application/s by going to its menu and selecting "Close". Unfortunately, according to Macscripter, OSX applications do not support this.
    Which makes me wonder why it is such an obvious part of AppleScript Editor's GUI. A cruel joke by Apple perhaps?

  • Report gets cancelled or terminated after eight hours

    While doing load testing of reports, all of my reports got cancelled or terminated after eight hours. I bang the report server and database with 30 long running reports using RWCGI60. The rwcgi60/showmyjobs shows that all are running for 8 hours and after that boom... all gets cancelled one by one with in a five minute period. I still see the SQL session activity on database. The report server log says the server engines are crashed one after the other. I have Maxengine set to 15. When I submit 30 reports I see 15 running and 15 enqueued.
    Is there any timeout parameter set on RWCGI60 where by it lost contact of database? RWCLI60 works fine and finished all reports.
    Thanks and Please let me know if you further information...

    Hi
    The timeout is a seeting in http server on which you host Reports CGI. Once that time limit is reached and no output is written, the web server would time out for that request. Reports CGI does not have any timeout parameter property.
    Thanks
    Rohit

  • Why do I have mysterious cellular data usage (Verizon) every 6 hours on all 3 of my iphone 5's?

    I have recently uncovered mysterious cellular usage on three different iPhones. I am a Verizon customer and discovered this by examining the cellular data use logs. What I found are a long series of mysterious data usage logs. I have visited the Genius Bar at my local Apple Store 3 times now to log notes and discuss the issue. It is being escalated.
    The characterstics are as follows:
    All my family phones have the appropriate IOS and hardware updates (verified by the GeniusBar at my local Apple Store).
    This is occuring across three phones, which happen to all be iphone 5. Two are 5 and the other a new 5s. We do have one iphone 4 in the family but the issue (so far as I can tell), is not happening on it.
    One iphone 5 has IOS 7, the other IOS 6. The new 5s has of course IOS 7.
    Mysterious data use happens even while connected to wifi.
    Each mysterious data use log entry is exactly 6 hours apart. For example: 2:18 AM, 8:18 AM, 2:18 PM, 8:18 PM, 2:18 AM ... etc. It cycles AM and PM, same times, for a day to many days until some condition causes it to change (evolve).
    The times evolve. One day it could be cycling through at one time series, then it changes to another time sequence and continues until the next condition.
    The data usage is anywhere from a few K to many MB. The largest I've seen is over 100 MB.
    The logs clearly show these usages are not due to human interaction. It is a program.
    If cellular connection is used frequently (by the owner), the pattern is hard to pick out. Luckily, my family member is very good about only using wifi whenever possible, so these mysterious use patterns are easy to pick out.
    Verizon allows access to 90 days worth of data logs, so I downloaded and analyzed them. This has been happening for at least 90 days. I have found 298 instances of mysterious use out of 500 total connections to cellular. A total of 3.5 GB of mysterious cellular data has been recorded as used in that 90 days by this phone alone. Only .6 GB of the total cellular data use is legitimate, meaning by the person.
    This issue is occuring across three different phones. Two are iPhone 5, and the third is a recently purchased iPhone 5s. The 5s I have not touched beyone the basic startup. I have left it alone on a desk for 3 days, and looking at the logs, the mysterious data use in the same pattern is occuring.
    So ... I am speaking to both sides, Verizon and Apple to get answers. Verizon puts their wall up at data usage. It doesn't matter how it is being used, you simply need to pay for it. Yes, the evidence I have gathered is getting closer to someting on Verizon's end.
    Before pressing in that direction, I am hoping someone reading this may recognize this issue as a possible iPhone 5 issue ... OR ... you, right now, go look at your data usage logs available through your carrier's web account, and see if you can pick out a pattern of mysterious use. Look especially at the early morning instances when you are most likely sleeping.
    I am hoping this is a simple issue that has a quick resolution. I'm looking for the "ooohhh, I see that now ..." But I am starting to think this might be much bigger, but the fact is, most customers rarely or never look at their data usage details, much less discover mysterious use patterns.
    The final interesting (maybe frightening part) thing about all this is that I discovered while talking to Verizon ... they do not divulge which direction the data is going. This goes for any use, mysterious or legitimate. Is cellular data coming to your phone, or leaving it? Is something pulling data from your phone? We know that it is possible to build malware apps, but the catch with my issue is that it is also happening on a brand new iphone 5s with nothing downloaded to it.
    Thanks for your time

    Thanks for the replies. It took a while not hearing anything so thought I was alone. I have done many of the suggestions already. The key here is that it occurs on both phones with apps, and phones still packaged in a box.
    A Genius Bar supervisor also checked his Verizon data usage log and found the same 6 hour incremental use. Suprisingly, he did not express much intrigue over that. Maybe he did, but did not show it.
    I think the 6 hour incremental usage is the main issue here. I spoke with Verizon (again) and they confirmed that all they do is log exactly when the phone connected to the tower and used data. The time it records is when the usage started. I also found out that the time recorded is GMT.
    What is using data, unsolicited, every 6 hours?
    Why does it change?
    Why does it only happen on the iPhone 5 series and not the 4?
    Since no one from Apple seems to be chiming in on this, and I have not received the promised calls from Apple tech support that the Genius Bar staff said I was suppose to receive, it is starting to feel like something is being swept under the rug.
    I woke up the other day with another thought ... What application would use such large amounts of data? Well ... music, video, sound and pictures of course. Well ... what would someone set automatically that is of any use to them? hmmm ... video, pictures, sound. Is the iPhone 5 succeptible to snooping? Can an app be buried in the IOS that automatically turns on video and sound recording, and send it somewhere ... every 6 hours? Chilling. I noted that the smallest data usage is during the night when nothing is going on, then it peaks during the day. The Genius Bar tech and I looked at each other when I drew this sine wave graph on the log print outs during an appointment ...

  • Movie rental Q: How many times can you watch the film within 48 hours?

    It's just I have 8 hours left on Into The Wild and I fancied watching it a second time, only it is not playing when I click on the thumbnail. It just says "accessing the iTunes store" for a few seconds. I've tried clicking play. Other films appear to work ok, just not this one. I assume that if it doesn't let me watch it a second time iTunes will give me free movie rental credit.

    According to the FAQ "Once you've started to watch the movie, you have 24 hours to finish watching the movie (even if you start watching before the download is complete). You can watch the movie as many times as you want within this 24-hour period": iTunes Store movie rental usage
    If you are having problems you should contact iTunes Store Customer Services.

  • I've just upgraded to IOS 7.0 on my iPhone 5 and the calendar is horrible!  I want to be able to see the who day at a glance not a few hours.  Does anyone have any suggestions?

    What's happened to the calendar in IOS 7.0?  I would like to be able to see the whole day at a glance not just a few hours.  Any suggestions?

    I know what it looks like and what it does.  I need to be able to see the whole day!  A few hours is not helpful for knowing whats ahead.  I don't want to scroll I just want to be able to look at a glance.  Does anyone have any helpful suggestions.

  • 12 hours view in iCal

    Can I make iCal show 12 hours view than 24 hours? It would make my life so much easier. I get my events mix up in 25 hours format. Thanks.

    Greetings,
    Don't know which question you are asking, so I'll try and handle both that it could be.
    To switch from 24 hour numbering to 12 hour numbering you need to go to System Preferences/International/Formats and either change to a country that has 12 hour formatting, or choose custom and choose 12 hour formatting.
    If you want to only see 12 hours on the screen that requires that you change the preference in iCal to show just the number of hours you wish to see, and then scroll the page to where they are where you would like them. Then quit the program and restart, and it will restart with those hours showing.

  • Hours per day, iMac Help solution doesn't work

    My weekly view in iCal shows 24 hour days. I need only 8 am to 10 pm, 14 hr days. I went to iCal>Prefs>general and changed it to those hours and to show only 14 hour days. This affected NO change in iCal though iCal Help says;
    "To change the days of the week or the number of hours that appear in the main calendar view, choose iCal > Preferences, and make your choices from the Week and Day pop-up menus in the General pane. For example, you can choose to only see the hours from 9AM to 5PM on Monday through Friday."
    iCal>Preferences>general pane does not offer me week and day pop up menus as the help item suggests.
    I'm trying to switch from Now Up-To-Date to iCal. Surely apple hasn't released a calendar program that can't be adjusted as desired. (I found one thread on these discussion forums but it was 34 pages long: I found no solution in the first 3 pages and figured i'd post here, as it doesn't seem reasonable to have to read 34 pages x 15 posts/page to get an answer to such a simple question.
    I hope someone will be nice enough to point out the solution i'm overlooking.
    thanks

    Hi Dan,
    Thanks. I agree that provides a hack of sorts to achieve my goal. But can we also agree that it's a workaround unworthy of apple (or anyone's) quality software? I mean, a calendar program that by default shows all 24 hours and CAN'T have that changed, only the portion of it that shows at first?
    And if this is the only solution, what, then, is the usefulness of the preference i've changed to read: "Show 14 hours at a time" ?
    thanks
    terry

  • Print ical weekly view with fewer hours

    When I print iCal in a weekly view, It prints 24 hours.  Obviously that isn't necessary.  How can I get it to print only 12 hours or the hours I have on my schedule?

    I was able to figure it out.  Apparently I had the times in wrong for an event and it went from pm one day to am the next day, hence prining 24hr.  When I corrected this is solved my problem.  Thanks for your patience.

Maybe you are looking for