Days between dates based on a 360-day calendar (10g)

Hello
does anyone know how to calculate days between dates based on a 360-day calendar (12 months to 30 days, used by merchants)? I use Oracle 10 g.

Thank you for the help
Best regards
Carsten
SQL*Plus: Release 10.1.0.4.2 - Production on Thu May 26 10:28:15 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Beta

ANTON@XE>with t as (
  2    select date '2011-04-04' as date_to, date '2011-02-02' as date_from from dual union all
  3    select date '2011-04-01', date '2011-02-02' from dual union all
  4    select date '2011-03-18', date '2011-02-02' from dual union all
  5    select date '2011-02-04', date '2011-02-02' from dual union all
  6    select date '2011-02-01', date '2011-01-31' from dual union all
  7    select date '2011-02-02', date '2011-02-02' from dual
  8  )
  9  select date_from, date_to
 10       , least( extract( day from date_to ), 30 ) - least( extract( day from date_from ), 30 )
 11       + 30 * ( extract( month from date_to ) - extract( month from date_from ) )
 12       + 360 * ( extract( year from date_to ) - extract( year from date_from ) ) days360
 13  from t
 14  /

DATE_FROM       DATE_TO            DAYS360
--------------- --------------- ----------
02-FEB-11       04-APR-11               62
02-FEB-11       01-APR-11               59
02-FEB-11       18-MAR-11               46
02-FEB-11       04-FEB-11                2
31-JAN-11       01-FEB-11                1
02-FEB-11       02-FEB-11                0

6 rows selected.

ANTON@XE>

See also http://en.wikipedia.org/wiki/360-day_calendar

Tags: Database

Similar Questions

  • Try an example date-based pivot

    Well, I spent the last few hours several looking at examples on how to convert data based on columns. I know what I want and what I have - I hope some of you kind, experienced can help me bridge the gap.

    What we try to do is run an employee performance evaluation. Every day an employee works, we count the number of hours that he/she works (and Yes, if there is no sheet we assume zero hour). What I have to do is to get a report that indicates a period of time (I convinced the boss to go in every two weeks for the coding of sake to avoid an undetermined number of columns). What I want to do, is take the data that looks like this:
    EMP_ID  TASK_HRS  EQ_HRS  DATE_INDEX
    87074     4     4     10-MAR-09
    80111     12     7     20-MAR-09
    80387     12     8     20-MAR-09
    80244     12     11     20-MAR-09
    81572     11.75     6     20-MAR-09
    87010     12     8.1     20-MAR-09
    81547     12     5.8     20-MAR-09
    84444     12     3     20-MAR-09
    80255     12     11     20-MAR-09
    80257     12     6     20-MAR-09
    84242     12     9     21-MAR-09
    and turn it into this:
    EMP_ID   20-MAR-09   21-MAR-09   22-MAR-09  ...   03-APR-09
    80111      12                   11                12.5    ...         11
    87010      12                    0                 11.5    ...         12
    ...
    For now, ignore the EQ_HRS column.

    At the end of the day, I will use the number of hours to generate a productivity rating based on other information of another view, but if I could get this far, the rest would be pretty straighforward. The part that I can't find a good explanation on how is generating the query to count the lines that pivots in the columns. I can see some examples, but I can't grasp the concept of how the pivot that happens. I would appreciate any help/explanation/example that would apply.

    Oh, and I'm on 10g, so I can't take advantage of the PIVOT 11 g feature for now (unfortunately).

    Hello

    This you will get 15 consecutive days, from a setting: start_date

    SELECT    emp_id
    ,       NVL (SUM (CASE WHEN date_index - :start_date = 0 THEN task_hrs END))     AS day_0
    ,       NVL (SUM (CASE WHEN date_index - :start_date = 1 THEN task_hrs END))     AS day_1
    ,       NVL (SUM (CASE WHEN date_index - :start_date = 2 THEN task_hrs END))     AS day_2
    ...
    ,       NVL (SUM (CASE WHEN date_index - :start_date = 15 THEN task_hrs END))     AS day_15
    FROM       table_x
    WHERE       date_index     BETWEEN :start_date
                     AND     :start_date + 14
    GROUP BY  emp_id
    ORDER BY  emp_id;
    

    Here is basically how it works.
    'GROUP BY emp_id' means that you will get a line by emp_id.
    Each of the last 15 columns sums up the task_hrs for a particular day in the range of 15 days. You will never have more than 1 row per employee per day: that is correct. You still need an aggregate as SUM function, because you're grouping BY emp_id.

    In SQL *, you can name the columns dynamically (for example "20 March 09", "21 March 09",..., "April 3 09" "") using variables substitution and COLUMN... NEW_VALUE.

    If date_index is not always midnight, use TRUNC (date_index) above.

    The query above will display only employees who have at least one line in the table in covered time interval.
    If you want to include all employees, even if they have 0 in the daily column, then OUTER JOIN for the employee table (or any table that has one row per emp_id).

    Generating the productivity index will likely be easier on non-dynamic data.

    Published by: Frank Kulash, March 25, 2009 15:01

    Published by: Frank Kulash, March 25, 2009 17:23
    Sorry, I forgot the 2nd argment (0) to NVL. I see you fixed.

  • code succcessive to genereate difference between dates in a table

    First create and insert statements;
    create table schedule(iloan_code number , schedule_date date);
    
    insert into schedule values(1001, to_date('01-jun-2012'));
    insert into schedule values(1001, to_date('01-jul-2012'));
    insert into schedule values(1001, to_date('01-aug-2012'));
    insert into schedule values(1001, to_date('01-sep-2012'));
    insert into schedule values(1001, to_date('01-oct-2012'));
    commit;
    The output of the table of the ANNEX should be now like this:
    ILOAN_CODE     SCHEDULE_DATE
    1001              01-JUN-12
    1001              01-JUL-12
    1001              01-AUG-12
    1001              01-SEP-12
    1001              01-OCT-12
    We want an additional column by name as well as the existing columns DAYS that would be the difference between dates.

    First line should be the difference between sysdate as well as the date of June 1, 2012 and successive lines must be the difference between successive calendar date

    For example in the second row the DAYS column should represent the difference between 1 July 2012 and 1 June 2012 and so on for the following ranks too.

    We need get the result by a SELECT statement

    The output of the table in the ANNEX must be something like that.
    iloan_code      schedule_date     days     Logic which we need 
    1001     1-Jun-12     22     sysdate-1st June 2012
    1001     1-Jul-12     30     difference between 1st July 2012 and 1st June 2012
    1001     1-Aug-12     31     difference between 1st aug 2012  and 1st July 2012
    1001     1-Sep-12     31     difference between 1st sep  2012 and 1st aug  2012
    1001     1-Oct-12     30     difference between 1st oct 2012 and 1st sep 2012
    Please notify;

    Hello

    You can change the Hoek solution like this:

    SELECT    iloan_code
    ,             schedule_date
    ,             schedule_date - LAG ( schedule_date
                                , 1
                         , TRUNC (SYSDATE)
                         ) OVER (ORDER BY schedule_date)     AS days_between
    FROM      schedule
    ORDER BY  schedule_date
    ;
    

    If all schedule_dates will be after SYSDATE, then you need not the CASE expression to test if it is.
    The argument optional 3rd to LAG is a return value in case there is no previous line.

    Sri says:
    ... The output of the table in the ANNEX must be something like that.

    iloan_code      schedule_date     days     Logic which we need
    1001     30-Jun-12     07     sysdate-30June 2012
    1001     1-Jul-12     30     difference between 1st July 2012 and 30 June 2012 ...
    

    The difference between 30 June 2012 and July 1, 2012 is not only 1 day?

  • Search between Dates

    It's confusing, so I'll do my best to explain.

    We have an application where employees sign out of the office. They provide it userID, LeaveDate and ReturnDate and it is written in a single record in SQL.

    There are also several searches for this data, which is to enter a user name and two dates and return if this user is disconnected between these two dates if the LeaveDate is now between the two search dates.

    The problem is that if someone was taken out of the 8 to 15, and a search was made on them for the 11th to the 13th, he would not return anything that either since the (8th) LeaveDate do not fall between the two search dates.

    So now, I am loaded with a way to solve this problem. Is there a search between dates and determine whether any date within this range is in the range of dates that the employee is disconnected? Is it possible, when the employee signs, create a record for each date in the span of days they have disappeared? So if someone out of the 10th to the 12th, it would create three different entries.

    Any help is appreciated.

    > return if this user is disconnected between these two
    > dates if the LeaveDate is between the
    > search two dates

    Start by creating some examples of date that will cover all the possibilities. As

    If the dates of research are:

    Search Start = 11
    End of search = 13

    You want to include these cases

    1 Date1 is before you start to search for... AND. Date2 is between start and end search
    Example: 6 to 13

    2 Date1 is between start and end search... AND... Date2 is after end search
    Example: 9th and 17th

    3 Date1 is between start and end search... AND... Date2 is between start and end search
    Example: 7-12

    4 Date1 is before you start to search for... AND... Date2 is the result of research
    Example: 5-21

    Then translate these terms to sql and test with some sample values. If your fields contain dates that comparisons are simple. If they contain a date and time don't forget to report both in your comparisons.

    There are better ways to write this, but here's an example of how you might begin to translate the above 4 conditions. Once you have the job of the initial query, you can improve the sql.

    Pseudo-CF/SQL

    WHERE (Date1< #start#="" and="" date2="" between="" #start#="" and="" #end#="">
    OR (Date1 BETWEEN #Start # AND #End # AND Date2 > #End #)
    OR (Date1 BETWEEN #Start # AND #End # AND Date2 BETWEEN #Start # AND #End #)
    OR (Date1 < #start#="" and="" date2=""> #End #)

  • Difference between Date of invoice and Date GL accounting Date Oracle AP

    Hello

    I have a question that might help a lot of people too late.
    I tried to run these queries
    Select aia. INVOICE_ID
    of AP_INVOICES_ALL aia, aida AP_INVOICE_DISTRIBUTIONS_ALL
    where aia. INVOICE_ID = aida. INVOICE_ID
    and aia. INVOICE_DATE <>aida. ACCOUNTING_DATE

    Select aia. INVOICE_ID
    of AP_INVOICES_ALL aia, aida AP_INVOICE_DISTRIBUTIONS_ALL
    where aia. INVOICE_ID = aida. INVOICE_ID
    and aia.GL_DATE <>aida. ACCOUNTING_DATE

    I see that there are a lot of results for these queries, where the Date of the invoice is not equal to the posting date and of the GL_Date of an invoice does not match the posting date in the distribution table.
    So, what is the difference between these dates.
    And if I had to take the date of posting of the invoice of the document, the date on which I have to take for these invoices in AP

    Thank you
    Bob

    Hello

    Date of GL:

    The date used to determine the right time of accounting for the transactions of your invoice and payment of GL. You assign a GL Date on your invoice during invoice entry
    and your payments during the creation of payment.

    Date of invoice:

    The invoice date that you assign to an invoice, you enter in Payables. Accounts payable uses this date to calculate the invoice due date, the terms of payment of the invoice. The invoice date may be the date of the invoice, or it can be another date that you specify.

    Posting date:

    The GL Date for distributions of the invoice. If you do not enter a value here or enter a value for GL Date when you submit Payables Open Interface Import, accounts payable will allocate a GL Date based on the GL Date set in the region of the invoice of the Payables Options window.

    Kind regards
    Rahul

  • Is it possible to migrate ESXi host between data centers, if so please provide a brief not

    Hi friends,

    1. is it possible to migrate ESXi host between data centers, if so please provide a brief walking distance.

    2 can we perform vMotion and Storage vMotion while ESXi is turned on.

    3. is it possible to extend the VMDK disk while it integrates snapshots in it.

    Best regards,

    Sirot Vijay

    Yes the vmotion and svmotion works but one by one.

    1 - vmotion is posssible to power on State, but you can't svmotion the vm simultaneously. The storage will remain same

    2 svmotion is also possible to power on the State, but you cannot vmotion virtual machine simultaneously. the host will remain the same.

    3 vmotion and svmotion is possible together when the vm is off power. the host and storage can be changed simultaneously on this State.

  • Migration of VMs between data warehouses

    I added a new data store to a vSphere 5.5 infrastructure and created a few scheduled tasks to migrate under tension on the virtual machines between data warehouses.

    The migration is successful, but on the source data store, I still see a lot of files for some migrated VMs, including the .vswp and vmware files - xx.log.

    This means that the scheduled task has failed?

    What have I to do to completely move virtual machines?

    Should I turn off and turn on the virtual machine?

    Concerning

    Marius

    Maybe this file are simply zombie files, generated cause an improper shutdown of the VM (take a look at the date of creation/modification of files). You can try to rename these files, if you are able to do so, these files aren't really in use. After you rename and make sure that the virtual machine works as expected, you can manually delete the files.

  • Move VM between data on the same vCenter centers

    Hey all the...

    With a virtual machine off, I'm migrating a VM between data centers in the same vCenter. There is no shared storage, different networks to the destination host. The user interface works (caveat about the missing shows destination network), yet move-vm does not work between data centers.

    By train: move-vm - vm test-20150309 - destination esx1 datastore - datastore1, I get the error:

    Move-vm: 09/03/2015-14:48:20 Move - VM Destination container must be in the same data center.
    On line: 1 char: 1
    + move-vm - vm test-20150309 - destination esx1. ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo: InvalidArgument: (esx1:VMHostImpl) [Move-VM], VimException
    + FullyQualifiedErrorId: Client20_VmHostServiceImpl_CheckMoveVmParameters_InvalidDatacenter, VMware.VimAutomation.
    ViCore.Cmdlets.Commands.MoveVM

    The manual States -Destination can be file, host, cluster etc... As the hosts AND records are bound by data centers, I guess it must know the new host & the new folder. I tried to use - destination twice, and I've tried - destination host, folder.

    Move-VM: cannot bind parameter because the 'Destination' is specified more than once. To provide several parameter values that can accept multiple values, use the table syntax. For example, '-parameter value1, value2, value3 ".

    Move-VM: missing an argument for the parameter "Destination." Specify a parameter of type 'VMware.VimAutomation.ViCore.Types.V1.Inventory.VIContainer' and try again.

    I used PowerCLI 5.8 and tried on 5.0 and 4.0 vCenter.

    Move-vm: 09/03/2015-14:48:20 Move - VM Destination container must be in the same data center.
    On line: 1 char: 1
    + move-vm - vm test-20150309 - destination esx1. ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo: InvalidArgument: (esx1:VMHostImpl) [Move-VM], VimException
    + FullyQualifiedErrorId: Client20_VmHostServiceImpl_CheckMoveVmParameters_InvalidDatacenter, VMware.VimAutomation.
    ViCore.Cmdlets.Commands.MoveVM

    The SDK method works?

    See 3. Re: to a different vm datacenter 

  • Movimentacao between data warehouses

    Pessoal, tirem minhas questions, please:

    Preciso mover some VMs between data warehouses, para Espaço realocacao, mas o client não possui o Storage VMotion. Then devo mover na mao mesmo:

    1. Desligar o servidor
    2. Remover o servidor inventario
    3. Mover a pasta server between os data warehouses (explore data store / move directory)
    4. Readicionar o servidor ao inventario
    5. Ligar o servidor

    É ISSO, certo?

    Estava pensando numa coisa, mas não sei is da certo e be e certo fazer.

    SE EU mudasse an ambiente licença para LICENÇA (FREE) AVALIAÇÃO, dai todos os recursos ficariam habilitados, como e por padrão na versão Avaliação. The EU Dai usaria o Storage VMotion e depois colocaria a licença of volta.


    Acham as daria certo?

    Abraço,


    Sena.

    Atanagoras Sena says:

    Pessoal, tirem minhas questions, please:

    Preciso mover some VMs between data warehouses, para Espaço realocacao, mas o client não possui o Storage VMotion. Then devo mover na mao mesmo:

    1. Desligar o servidor
    2. Remover o servidor inventario
    3. Mover a pasta server between os data warehouses (explore data store / move directory)
    4. Readicionar o servidor ao inventario
    5. Ligar o servidor

    É ISSO, certo?

    Perfeito. Isso AI.

    Estava pensando numa coisa, mas não sei is da certo e be e certo fazer.

    SE EU mudasse an ambiente licença para LICENÇA (FREE) AVALIAÇÃO, dai todos os recursos ficariam habilitados, como e por padrão na versão Avaliação. The EU Dai usaria o Storage VMotion e depois colocaria a licença of volta.

    Acham as daria certo?

    Daria, very e "ilegal" você fazer isso SIM. MAS funcionaria na boa too.

    ABCs

    Don't atribuir os pontos não

  • Copia VM between data automated warehouses

    Is, I need if any can help me, I need building una tarea me Permite automatizar her copia (CLONADO) una o several VMs desde one Datastore hacía otro.

    Desde is muchas gracias

    Rolando Kohl

    Como estas?

    If cerebro scheduled task ordered realize esto, podes clonar between hasta between data centers.

    Saludos.

  • Heart rate between data centers

    Hello

    I made a VMware installation only when we have two datacenters with a host and a disk on each data center system, vi have 2 x 4 GB FC between data for the availability of the storage centers and we have 2 x 1 Gbit L2 connections between data (network, vmotion and HB) centers.

    Now my problem is pulsation HA making only redundant you normally just add two natachasery to the switch, but in my case I need to run my heart rate on two different VLANS to ensure that it also works on different connections between data centers.

    If I just add another service console and configure a new vlan with default gateway, dose anyone know if it will work?

    Daniel

    Hi Daniel,.

    Welcome to the forums.

    You can take a look at the following KB on the Service Console redundancy for VMware High Availability.

    It will be useful.

    Concerning

    Franck

  • Clone between data centers and through the firewall?

    I have a VC that manages 8 virtual data centers.  Some of these data centers are on a dish network, and some are in a demilitarized zone.  Even if the storage is NOT shared between data centers, I am able to clone a VM between data on food networks centers but I cannot clone between a data center on a dish network and the other in a demilitarized zone.

    Is there a specific port that must be open to clone through a firewall, or I wouldn't be able to do this.

    ________________________________

    Jason D. Langdon

    The file copy occurs using port TCP/UDP 902, as all communications from ESX.

    Do you have any NAT between the servers ESX and vCenter?

    Marcelo Soares

    VMWare Certified Professional 310/410

    Master virtualization technology

    Globant Argentina

    Review the allocation of points for "useful" or "right" answers.

  • block of data based on a stored procedure with the input arguments

    Hello

    I am able to create a block of data based on the stored procedure.
    but I want that procedure to take both of the input arguments and I am facing issue while setting the value for this input arguments from another block element.
    Please someone help, how to set the value of the input of another block-element of control argument? (Note: data block is based on the stored procedure)

    Thanks in advance,
    Jean François Anandan

    I have an example that really works

    in the ownership of block

    arguments of data source query that you have two sections

    names one argument he write the name of the argument on the right, type the setting, fashion and value: block1.name and then pass the value to the procedure

  • How to get LASTDAY for each month between data dates...

    Hi friend

    I have a doubt, how to get LASTDAY for each month between data dates...

    for ex:
    My contribution will be like this
    date = 01/12/2011
    To date = 14/04/2011

    And I need an output like
    31/01/2011
    28/02/2011
    31/03/2011

    is it possible to achieve through sql query in oracle
    Thanks in advance for all friends to help him

    Hello

    Something like this (assuming that the dates are originally VARCHAR2s):

    SQL> var dt_start varchar2(10)
    SQL> var dt_end varchar2(10)
    SQL> exec :dt_start := '12-01-2011'
    
    PL/SQL procedure successfully completed
    
    SQL> exec :dt_end := '14-04-2011'
    
    PL/SQL procedure successfully completed
    
    SQL>
    SQL> select last_day(
      2           add_months(
      3             trunc(to_date(:dt_start,'DD-MM-YYYY'),'MM'),
      4             level-1
      5           )
      6         ) as result
      7  from dual
      8  connect by level <= months_between(to_date(:dt_end,'DD-MM-YYYY'), to_date(:dt_start,'DD-MM-YYYY'))
      9  ;
    
    RESULT
    -----------
    31/01/2011
    28/02/2011
    31/03/2011
     
    

    If the dates are already of the date data type, simply remove the to_date function.

  • Extract data based on the year and month

    My clients have taken a field TimeStamp DB Oracle and downloaded the access in a TEXT field format.
    Samples: 20060401001348CS

    Everything I'm doing is extracted from the data based on the year and the month. I equal to 200604 *, 200604%. Have also tried to use AS.
    Nothing works. It may just be that dificult. Help, please. Thank you

    Mike

    I'm SO sorry. I have 35 years of Experinece in this area and I have my data (assuming) was all a 200604 date and he was not. The query did work. I'll have more questions and that you do not want to loose credability with this site. Again, I am sorry. Sincere to help thanks.
    Ron

Maybe you are looking for

  • 5 button iPod home not working and locked.

    Hey, some time ago I came across a problem where my just stuck home button up one was insensitive. It wasn't a big deal since I had open contact. But now my iPod 5A locked again where it won't turn on, charge or get recognized I have iTunes and I am

  • Comments are not loading in Firefox

    Dear reader, For some time (six months)? I have a problem with Youtube & loading comments. Firefox works fine, too Youtbe. Except: comments will be loaded! I see interminable wait with "loading" icon I looked on the Internet and various No., but foun

  • Portege R100 - Random Blue Screen of Death (IRQL not less or equivalent)

    Hello I've been making 'Blue Screen of Death' screens random in the last few weeks. The error is "IRQL not less or equal ' and it performs a memory dump each time. If I get the error and try to restart the phone after, I usually get the same screen o

  • HP LaserJet Pro CM1415fnw color multifunction printer - cannot FIND the WIRELESS NETWORKS

    PRINTER: HP LaserJet Pro CM1415fnw color multifunction printer OS: Windows 7 OWNER: More than 2 years without any problem LOCATION/SET-UP: To my personal residence. All-in-one router through the cable company. QUESTION: Suddenly, printer cannot find

  • Z3 blackBerry 0015 error

    Black berries appear www.bberror.com/bb10-0015 z3