Identify DayOfWeek within date range

Post Author: mcatd
CA Forum: Formula
I need to write a report counting employee absences for each day within a user-selected week. The employee-absence records I have to work with look more or less like this:
Employee Name      Absence Type     Abs Start Date    Abs End DateSmith                                 S                   02/14/07             02/15/07Jackson                             V                    02/12/07             02/16/07Tulowitzki                           S                    02/15/07             02/16/07
The report needs to look like this:
DayOfWeek        Sick    VacationMonday                  0           1Tuesday                 0           1Wednesday            1           1Thursday                2           1Friday                    1           1
I am completely stumped on how to assign a DayOfWeek value to those dates that are only implicit in the range, particularly as the size of the range varies from one record to the next.          

Post Author: SKodidine
CA Forum: Formula
This is a bit messy and cumbersome but works.  Perhaps others have a better idea.
Create all these formulae:
processdates  (Place this formula in your details section and suppress it)
numbervar sunsick;
numbervar sunvac;
numbervar monsick;
numbervar monvac;
numbervar tuesick;
numbervar tuevac;
numbervar wedsick;
numbervar wedvac;
numbervar thusick;
numbervar thuvac;
numbervar frisick;
numbervar frivac;
numbervar satsick;
numbervar satvac;
datevar startdate := date(2007,02,12);  // abs start date
datevar enddate   := date(2007,02,16); // abs end date
stringvar type    := 'v';                                        // type
datevar pdate := startdate;
while pdate <= enddate do
select dayofweek(pdate)
case 1:
(if type = 's' then
sunsick := sunsick + 1
else if type = 'v' then
sunvac := sunvac + 1;)
case 2:
(if type = 's' then
monsick := monsick + 1
else if type = 'v' then
monvac := monvac + 1;)
case 3:
(if type = 's' then
tuesick := tuesick + 1
else if type = 'v' then
tuevac := tuevac + 1;)
case 4:
(if type = 's' then
wedsick := wedsick + 1
else if type = 'v' then
wedvac := wedvac + 1;)
case 5:
(if type = 's' then
thusick := thusick + 1
else if type = 'v' then
thuvac := thuvac + 1;)
case 6:
(if type = 's' then
frisick := frisick + 1
else if type = 'v' then
frivac := frivac + 1;)
case 7:
(if type = 's' then
satsick := satsick + 1
else if type = 'v' then
satvac := satvac + 1);
pdate := pdate + 1;
monsick
whileprintingrecords;
numbervar monsick;
totext(monsick,0);
tuesick
whileprintingrecords;
numbervar tuesick;
totext(tuesick,0);
wedsick
whileprintingrecords;
numbervar wedsick;
totext(wedsick,0);
thusick
whileprintingrecords;
numbervar thusick;
totext(thusick,0);
frisick
whileprintingrecords;
numbervar frisick;
totext(frisick,0);
monvac
whileprintingrecords;
numbervar monvac;
totext(monvac,0);
tuevac
whileprintingrecords;
numbervar tuevac;
totext(tuevac,0);
wedvac
whileprintingrecords;
numbervar wedvac;
totext(wedvac,0);
thuvac
whileprintingrecords;
numbervar thuvac;
totext(thuvac,0);
frivac
whileprintingrecords;
numbervar frivac;
totext(frivac,0);
In your report footer, create text objects for 3 headings such as "Day of Week", "Sick", "Vacation".  Under "Day of Week", create 5 text objects containing "Monday", "Tuesday", "Wednesday", "Thursday", "Friday". Place the appropriate formulae from above next to the appropriate day.
I tested it and it seems to work, so give it a shot.

Similar Messages

  • Function Module to Compare Date within date Range

    Hi All,
            Does anyone know Function Module to Compare Date within date Range...For example i need to find whether 08/02/2006 falls in between 07/15/2006 and 09/15/2006......

    data: datum type sy-datum value '20070802',
          datum_low type sy-datum  value '20070730',
          datum_high type sy-datum value '20070930'.
    If datum between datum_low and datum_high.
    Endif.
    Regards,
    Rich Heilman

  • Today's Date within Date Range

    I have a BeginDate and EndDate in a database.  I want to be able to list those records if todays date is within the date range of BeginDate and EndDate.  I am unsure of the coding on this.  Has anyone done this and can give me some help? Thanks.

    Error Occurred While Processing Request
    Variable GET is undefined
    Ok That is what I thought.  I have tried it without the # and I get There is an error in the syntax of the query.

  • How to display top n records(sorted by no of defects) within date range

    I would like to display top n production orders(sorted by defects linked with each order) within the date range entered by the user.
    Please advice.
    I have 3 parameters to my report:
    1. n(n is no of top records to be displayed)
    2. From date
    3. To date
    Appreciate quick response.
    Regards,
    Hari

    if you use the parameters in the report by placing them in the record selection it should display the records within your date range.
    if {date field} in ?start to ?end then true

  • Calculate Quarter within Date Range

    I have question regarding a date range.  I created a formula like so
    {SO_SalesOrderHistoryHeader.OrderDate} >=DateValue (2008,04,01) and {SO_SalesOrderHistoryHeader.OrderDate}<=DateValue (2008,06,30)
    I get my "True" which is fine, my problem is, what happens when it goes to the next year? Or I want to look at a previous year?  Do I have to go back and edit my formula? 
    Or is there a way to tell my formula to go by whatever year is entered?

    You can use the date range but the problem I forsee with it is which date are you going to use?  The start date or end date?  The choice also determines which date to use if the two dates span across years.  For example, if your date range is 2008-10-01 to 2009-03-31. 
    If the above situation will not occur, then you can use the dates of your date range thus:
    Modify your formula thus to use the year of the start date of your date range
    {SO_SalesOrderHistoryHeader.OrderDate} >=DateValue (year(minimum(?date range})) ,04,01) and {SO_SalesOrderHistoryHeader.OrderDate}<=DateValue (year(minimum(?date range})) ,06,30)
    Modify your formula thus to use the year of the end date of your date range
    {SO_SalesOrderHistoryHeader.OrderDate} >=DateValue (year(maximum(?date range})) ,04,01) and {SO_SalesOrderHistoryHeader.OrderDate}<=DateValue (year(maximum(?date range})) ,06,30)
    Hope this made things clear as mud

  • Grouping by month within date range

    Hi,
    I have a date range which I like to group by months, but not from the 1st to last date of the calendar month but by given start date.  For example the table below represents the date range with some values in a table.  So the
    first month range in the group should be from 06/06/2013 to 08/07/2013.  The 06/07/2013 is absent because it's Saturday.  In fact the data is populated with working days only.  
    Table below shows what I really would like to get:
    There is a simple calculation for each month anniversary date, if the value from the start date, 06/06/2013, here 12 is less than the next month anniversary date, 08/07/2013, which is 9, then it should ignore it.  And only show the value from the month
    who's anniversary date value is less than the first date value, 12.  So the example above shows value 14 for the second month's anniversary date, 06/08/2013.  If the value has been found in any month the show, and ignore the rest. 
    I am just interested if there are any and report which number of month and the value. 
    I can implement this in procedural way, such as in VBA, but because the above looped many times it will take hours to run the process.  I have tried in SQL Server, but first problem I came up with is that I can't group by month from the given start
    date.
     Is this possible to do in T-SQL ?

    I'm not sure I entirely understand your question.  So I'll break the answer into two parts.
    First, as I understand it, you are looking for a way to group data by months, but not all dates in June, 2013 as one group, all dates in July, 2013 as the next group, etc.  Instead you want all dates from June 6, 2013 to July 5, 2013 as the first month,
    all dates from July 6, 2013 to August 5 as the second month etc.  The way to do that is use
    DATEDIFF(month, '20130606', <your date column>) + CASE WHEN DAY(<your date column>) < 6 THEN -1 ELSE 0 END
    So you can assign the month number you want to every row when you select from your table by
    SELECT DATE, VALUE, DATEDIFF(month, '20130606', DATE) + CASE WHEN DAY(DATE) < 6 THEN -1 ELSE 0 END AS MonthNumber
    FROM <your table name>
    Now as I understand it (but am not sure), you want the first value in each "month" (as you are defining "month" which is greater than the value contained in your start date and if no value in a particular month is greater than that value,
    you don't want any row for that month.  For that you could do something like
    Declare @StartDate date;
    Declare @StartValue int;
    Set @StartDate = '20130606';
    Select @StartValue = Value From <your table name>
    Where Date = @StartDate;
    ;With cteMonthNumber As
    (SELECT DATE, VALUE, DATEDIFF(month, @StartDate, DATE) + CASE WHEN DAY(DATE) < DAY(@StartDate) THEN -1 ELSE 0 END AS MonthNumber
    FROM <your table name>
    WHERE DATE > @Date AND VALUE > @Value),
    cteOrdered As
    (Select DATE, VALUE, MonthNumber,
    ROW_NUMBER() OVER (PARTITION BY MonthNumber ORDER BY DATE) As rn
    From cteMonthNumber)
    Select MonthNumber, Value As KickOutValue
    From cteOrdered
    Where rn = 1;
    Tom
    P.S.  Notice that I wrote my date literal as YYYYMMDD.  This is a good idea in SQL Server since '20130806" will always be interpreted as August 6.  But depending on the settings on your server and/or client '06/08/2013' might be dd/mm/yyyy
    and so be August 6, but it might be interpreted as mm/dd/yyyy and be June 8.
    It is also a good idea to express date literals in this forum as yyyymmdd.  There are a lot of us on the forum from the United States and we think 06/08/2013 is June 6 and a lot of us from other places who think 06/08/2013 is Aug 8.  If you give
    your dates as yyyymmdd we don't have to try to figure out what format you are using.

  • Movement types in a date range

    Hi All,
    I need to get all the movement types occured in  date range for a material.
    I got movement types for material form MSEG but i need to specify within date range.
    Plz suggest.
    Thanx
    Rohit

    try it like this: you will get the movement type between this date & time range from mseg
    Select a~BWART
      into table t_itab
      from mseg as a inner join mkpf as b
        on a~MBLNR eq b~MBLNR
       and a~MJAHR eq b~MJAHR
    where b~BLDAT between l_BLDAT     and h_BLDAT
       and b~CPUTM between s_time-low  and s_time-high.
    or you want to check for a single movement type than
    Select single a~BWART
      into w_bwart
      from mseg as a inner join mkpf as b
        on a~MBLNR eq b~MBLNR
       and a~MJAHR eq b~MJAHR
    where b~BLDAT between l_BLDAT     and h_BLDAT
       and b~CPUTM between s_time-low  and s_time-high
       and a~BWART eq p_BWART.
    if sy-subrc <> 0.
    Endif.
    With luck,
    Pritam.
    Edited by: Pritam Ghosh on Feb 3, 2009 4:42 PM

  • Supress details in subreport based on date ranges in main report

    I am using Crystal XI R2 and am working with Human Resources Data.
    The main report is grouped on and generates a list of temporary teaching positions like this:
    Smith, John
         FTE_____Start Date_______End Date
          .3 ______09/01/2007______10/20/2007
          .2 ______10/05/2007 ______04/15/2008
          .2 ______04/01/2008 ______06/30/2008
    The subreport (generated from a different source, but linked to main report on ) generates a list of days the employee worked as a Teacher on Call:
         TOC Date______ Portion of Day Worked
         09/05/2007______1.0
         09/19/2007______0.6
         10/08/2007______0.4
         10/09/2007______1.0
          04/08/2008______0.6
          04/18/2008______1.0
    Employees are granted seniority for TOC days worked, EXCEPT when they are already employed in a Teaching position >=.4 FTE  (because they are already granted full seniority for that period), so I need to be able to suppress records that fall within date ranges listed in the Main Report where the combine FTE is >=.4.     
    I believe this question has two parts:
    1. how do I evaluate the date ranges to combine overlapping periods?  Results would look like this... (I don't need to be able to see this, but I'm assuming I'd have to create a date range with the results in order to answer question #2 - but I haven't worked much with ranges.)
        FTE_____Start Date______End Date
          .3______09/01/2007______10/04/2007
          .5______10/05/2007______10/20/2007 
          .2______10/21/2007______03/31/2008
          .4______04/01/2008______04/15/2008
          .2______04/16/2008______06/30/2008
    2. how do I supress the TOC dates in the Subreport that fall within the start and end dates of all the employee's positions >= 0.4 FTE ?  Supreport results for this example would look like this...
         TOC Date______ Portion of Day Worked
         09/05/2007______1.0
         09/19/2007______0.6
         04/18/2008______1.0
    (I will sum the "portion" values and mulitply them by a constant variable to complete the seniority calculation.)
    Thank you in advance for any assistance you may be able to provide!

    Thanks for your help Graham, I have continued to work with this and I took the BO Crystal III course.  Your suggestions gave me a sense of  direction.
    I was not able to share a date range array with the subreport (kept getting error messages saying "call BO" , but I WAS able to share the startdate array and the enddate array.  I also shared the fte values array. 
    I had wanted to use a loop  to check
    if TOCdate in startarray[x] to endarray[x]
    then ftearray[x]
    and  sum the new range of fte[x] values so that I could suppress any TOCdates where fte was >=0.4.   But I couldn't quite get there, I kept coming up with formulas that displayed only the first value or the last or zero.
    So I used the following formula for each index (returnindex value had to be changed for each case), then added them all together.
    shared datevar array startArray;
    shared datevar array endArray;
    shared numbervar array FTEArray;
    local numbervar arraylength:= ubound(startArray);
    local numbervar i;
    local numbervar returnindex :=-1;
    If arraylength >=1 then
    if not({AAATDDET.Date} in startarray[1]to endarray[1])then
    0 else
    if {AAATDDET.Date} in startarray[1]to endarray[1] then
    (returnIndex:= i;);
    i:=i+1;
    if returnindex =0 then
    ftearray[1]

  • Getting date range in Find User Form

    Hello experts,Actually my goal is to get list of users having termination date within date range.But here my problem is when i added this business logic in Find user form which does loop on all users i was unable to get the list of users having termination within date range as the termination date of user object is string.
    By gettting problem in the above way we tried to query date attribute of the task property of user object which is set with the value of termintion date when the user is created.The task property code is given below
    <Properties>
    <Property name='tasks'>
    <List>
    <Object name='Conseco Account Termination Date'>
    <Attribute name='date' value='01/10/2008'/>
    <Attribute name='task' value='Conseco Account Termination Date'/>
    </Object>
    <Object name='Sunset Date'>
    <Attribute name='date' value='2/22/2008'/>
    <Attribute name='task' value='Sunset Date'/>
    </Object>
    </List>
    </Property>
    </Properties>
    Could anyone help me in referring the date attribute of 'Conseco Account Termination Date' property

    Because the date is stored as a string, you'll need to use a different format. Use yyyy/MM/dd. You can use the stringToDate and dateToString methods.

  • Assign Month within a date range (by most days in a given month)

    I have a begin and end date, sample data as such
    select to_date('01-13-12','mm-dd-yy') from_dt,
    to_date('02-23-12','mm-dd-yy') to_dt
    from dual
    union all
    select to_date('03-15-2012','mm-dd-yy') from_dt,
    to_date('04-16-2012','mm-dd-yy') to_dt
    from dual
    union all
    select to_date('05-13-2012','mm-dd-yy') from_dt,
    to_date('07-23-2012','mm-dd-yy') to_dt
    from dual
    How do I assign a month by the most days in a month within that date range? Sometimes the date range might have the exact same amount of days in a month (like 3/15/2012 has 16 days and 4/16/2012 has 16 days). In this case, I want the earlier month (march).
    So from the sample data:
    01/13/2012, 02/23/2012, February
    03/15/2012, 04/16/2012, March
    05/13/2012, 07/23/2012, June
    Thanks
    Edited by: user4422426 on Mar 1, 2012 5:15 PM

    Hi,
    Here's one way:
    WITH     cntr          AS
         SELECT     LEVEL - 1     AS n
         FROM     (
                   SELECT      1 + MAX (to_dt - from_dt)     AS max_day_cnt
                   FROM     table_x
         CONNECT BY     LEVEL     <= max_day_cnt
    ,     got_r_num     AS
         SELECT     x.from_dt, x.to_dt
         ,     TRUNC (x.from_dt + c.n, 'MONTH')     AS month
         ,     count (*)                    AS cnt
         ,     ROW_NUMBER () OVER ( PARTITION BY  from_dt, to_dt
                             ORDER BY        COUNT (*)     DESC
                             ,             TRUNC (x.from_dt + c.n, 'MONTH')
                           )     AS r_num
         FROM       cntr     c
         JOIN       table_x  x  ON  c.n  <= x.to_dt - x.from_dt
         GROUP BY  x.from_dt, x.to_dt
         ,       TRUNC (x.from_dt + c.n, 'MONTH')
    SELECT     from_dt, to_dt
    ,     TO_CHAR (month, 'Mon YYYY')     AS mon
    ,     cnt
    FROM     got_r_num
    WHERE     r_num     = 1
    ;Thanks for posting code to create the same data. Please test your code before you post it: you got the order of arguments to TO_DATE reversed.

  • Sum amount within a date range

    I have 2 tables where I Need to sum up sales amount within a booking date range.
    Below an example to help illustrate this task.
    Table1:
    CustomerID BookingDate (YYYY-MM-DD)
    1 2014-04-29
    1 2014-07-30
    2 2014-03-31
    2 2014-06-30
    Table2:
    CustomerID SalesDate (YYYY-MM-DD) Amount
    1 2014-01-30 20
    1 2014-02-25 30
    1 2014-05-20 100
    1 2014-07-30 200
    1 2014-09-30 80
    2 2014-03-20 50
    Result:
    CustomerID BookingDate (YYYY-MM-DD) Sum(Amount From Table2)
    1 2014-04-29 50 -- SalesDate between 2014-01-01 and 2014-04-29
    1 2014-07-30 300 -- SalesDate between 2014-04-30 and 2014-07-30
    2 2014-03-31 50 -- SalesDate between 2014-01-01 and 2014-03-31
    2 2014-06-30 0 -- SalesDate between 2014-04-01 and 2014-06-30

    Please try this code:
    declare @Table1 table
    (CustomerID int,BookingDate date );
    insert @Table1
    values
    ( 1, '2014-04-29' ),
    (1, '2014-07-30' ),
    (2, '2014-03-31' ),
    (2, '2014-06-30') ;
    declare @Table2 table
    (CustomerID int, SalesDate date, Amount int);
    insert @Table2
    values
    (1,'2014-01-30',20) ,
    (1,'2014-02-25',30) ,
    (1,'2014-05-20',100) ,
    (1,'2014-07-30',200) ,
    (1,'2014-09-30',80) ,
    (2,'2014-03-20',50) ;
    with cte as
    select
    CustomerID,
    BookingDate ,
    row_number() over (partition by CustomerID order by BookingDate ) as rn
    from @Table1 )
    , cte2 as
    select
    T2.CustomerID ,
    isnull(T1.BookingDate, '2014-01-01') as FromDate,
    T2.BookingDate as ToDate
    from cte as T1
    right join cte as T2
    on T1.rn = T2.rn - 1
    and T1.CustomerID = T2.CustomerID
    select
    b.CustomerID ,
    b.ToDate as BookingDate,
    isnull(sum(a.Amount), 0) as [Sum(Amount From Table2)]
    from @Table2 as a
    right join cte2 as b
    on a.CustomerID = b.CustomerID
    and a.SalesDate > b.FromDate
    and a.SalesDate <= b.ToDate
    group by
    b.CustomerID ,
    b.ToDate;
    T-SQL Articles
    T-SQL e-book by TechNet Wiki Community
    T-SQL blog

  • Fetching information within the given date range

    Hello All,
    PLease can u help me in solving this : --
    I need to fetch those employees who will complete 18 yrs within the date range specified.
    For example, if date1 = 10/21/2008 and date2 = 11/03/2008
    then i need to display information of all those employees whose birthday fall within the date range along with the date.
    Thanks in advance !

    Hi,
    16:58:25 b1>desc test1
    Name                                      Null?    Type
    AGE                                                NUMBER
    BDATE                                              DATE
    16:58:36 b1>SELECT * FROM test1
    16:58:47   2  ;
           AGE BDATE
            18 23-OCT-08
            17 23-NOV-08
    16:58:48 b1>SELECT *
    16:58:55   2  FROM test1
    16:58:55   3  WHERE  Bdate BETWEEN  TO_DATE('21/10/2008','DD/MM/YYYY')  AND  TO_
    DATE('30/10/2008','DD/MM/YYYY');
           AGE BDATE
            18 23-OCT-08- Pavan Kumar N

  • Sum data for a given day within a given date range

    Anyone know how to add data in a coulumn if the adjacent column meets a specific date range? For example I want to add up hours flown (pilot logbook) in each specific month on a seperate type.

    Hi Jeff,
    Here's a simple example of how you might do this. Before getting involved with the EOMONTH function you can try a less compact (but somewhat easier to understand) approach. Add Year and Month columns to your log. You can extract the values from the date using the MONTH and YEAR functions or just enter them manually. Then do something like this:
    The formula in the B2 of the Year table, copied down, is:
             =SUMIFS(Log::$E,Log::$A,A2)
    The formula in C2 of the Month table, copied down, is:
             =SUMIFS(Log::$E,Log::$A,A2,Log::$B,B2)
    These two formulas look at the cell(s) to their left and pull the corresponding totals out of the Log table.
    Think of the arguments within SUMIFS as first the column of data to be summed, followed by column-criteria pairs.  The criteria are in the cells to the left. The columns are in the Log table.
    SG

  • Finding duplicates within a date range. SQL help please!!

    I have a table of records and I am trying to query the duplicate emails that appear within a given date range but cant figure it out.
    There records that it returns are not all duplicates withing the given date range.  HELP!!
    Here is my query.
    Thanks in advance.
    SELECT cybTrans.email, cybTrans.trans_id, cybTrans.product_number, cybTrans.*
    FROM cybTrans
    WHERE (((cybTrans.email) In (SELECT [email] FROM [cybTrans] As Tmp GROUP BY [email] HAVING Count(*)>1 ))
    AND ((cybTrans.product_number)='27')
    AND ((cybTrans.appsystemtime)>'03-01-2010')
    AND ((cybTrans.appsystemtime)<'03-05-2010')
    ORDER BY cybTrans.email;

    Yet another method...
    <cfset start_date = DateFormat('01/01/2007',
    'mm/dd/yyyy')>
    <cfset end_date = DateFormat('09/30/2009',
    'mm/dd/yyyy')>
    <cfset start_year = DatePart('yyyy', start_date)>
    <cfset end_year = DatePart('yyyy', end_date)>
    <cfset schoolyear_start = '09/01/'>
    <cfset schoolyear_end = '06/30/'>
    <cfset count = 0>
    <cfloop index="rec" from="#start_year#"
    to="#end_year#">
    <cfset tmp_start = DateFormat('#schoolyear_start##rec#',
    'mm/dd/yyyy')>
    <cfset tmp_end = DateFormat('#schoolyear_end##rec + 1#',
    'mm/dd/yyyy')>
    <cfif DateCompare(tmp_start,start_date) gt -1 and
    DateCompare(tmp_end, end_date) eq -1>
    <cfset count = count + 1>
    </cfif>
    </cfloop>
    <cfoutput>
    <br>There are #count# school year periods between
    #start_date# and #end_date#
    </cfoutput>

  • Obtaining data within a date range in XL Reporter

    Dear All,
    I'm currently working on BS in XL reporter.
    I was trying to extracting data in a date range, setting PER( Code >= @MthFrom Or Code <= @MthTo ) in report default tab.
    However, the result is shown as all data as of current date. E.g. Selection criteria: >=200808, <=200809, the result is shown as from Begining to 200810.
    Please kindly advise.
    Thank you.
    Regards,
    Julie
    Edited by: Julie Wan on Oct 1, 2008 1:10 PM

    Dear Gordon,
    Thank you for your reply.
    However my case is different to your given link.
    In my case, there is a result coming out, but not within the correct range i selected. It shows all instead.
    I tried to set the period range in report default tab,  in column tab of a expanding column, and in cell tab of an individual cell, but none have worked. E.g. PER( Code >= @MthFrom or Code <= @MthTo )
    Regards,
    Julie

Maybe you are looking for