Date Range Within a Date Range
I'm suffering from a mental block on this one and I'm hoping
someone here can help. What I need to do is determine how many date
ranges are between a broader date range. For example a school year
runs from 9/1 to 6/30 or 180 work days. What I need to do is
compute the number of 9/1 to 6/30 periods between say 1/1/2007 and
9/30/2009. The result of this find is used in othere calculations
in a rather complex report. Any help is appreciated.
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>
Similar Messages
-
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 PMHi,
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. -
How to capture the data within the given range of maximum and minimum values ? from csv files
My requirement,
1. Here, the user will provide the range like maximum and minimum values, based on this range, the VI should capture the data within the given range. ( from CSV file as attached )
2. Then VI should calcluate the average value for captured data and export it to excel.
This is my requirement can anyone help me on this.
Many thanks in advance
rc_cks
Attachments:
sample_short.csv 2439 KBHi,
Thanks for remnding me. I forgt to attach the VI,
Here I am attaching the VI, what I tried.
From attached CSV file, I have to find an average value for columns B,C,D,E,F,G,H,I and AJ, AK. ( data range will be defined by user ), focused only on these columns
Here, the scope is to calculate an average value for given data range by user as MAX and MIN data.
FYI: I tried manually for two instance i.e column H & I. As per H column one steady state values from 7500 to 10500 and similarly in I column 7875 to 10050. So, I gave these as a limit to capture and calculate the average value. But unfortunaltely, requirement has been modified as per below requirements.
More Info on requirement:
--> The user will define the range of data by giving some MAXIMUM and MINIMUM values(for above mentioned columns induvidually), then VI should capture that data range and it has to caculate the average value for that range of data. This is the task I have to complete.
--> I am stuck in creating a logic for data capturing for given range of MAX and MIN value from user,
Can anyone help me on this.
If my explanation is not clear, Please let me know.
Many thanks, help mw
rc
Attachments:
VI_rc.vi 25 KB
sample.zip 4166 KB -
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 -
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-30Please 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 -
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. -
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. -
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 -
Getting last-day-of-week dates within certain date range
Hi all,
I have the following Challenge:
I want to know the dates of the last day of all the weeks within a certain range of dates.
For instance if my range would be 01-jun-2002 - 31-jun-2002
then the returned days should be (lastday of the week is sunday):
. 02-jun-2002
. 09-jun-2002
. 16-jun-2002
. 23-jun-2002
. 30-jun-2002
I want to accomplish this by only using sql (no pl/sql) in a ora 8.0.x rdbms
How would I do this? (if it's possible)
Tia,
MartinChristian's solution returns
01-JUN-02
08-JUN-02
15-JUN-02
22-JUN-02
on my system. The first day of the week is dependent on NLS settings.
SELECT MAX(realdate)
FROM (
SELECT TO_CHAR(TO_DATE('31-may-2002','dd-mon-yyyy') + ROWNUM,'IW') weekno,
TO_DATE('31-may-2002','dd-mon-yyyy') + ROWNUM realdate
FROM all_objects
WHERE rownum <= TO_DATE('30-Jun-2002','dd-mon-yyyy') - TO_DATE('01-Jun-2002','dd-mon-yyyy')
GROUP BY weeknoThe IW format model give ISO standard week numbers and a week always starts on Monday. -
How to select data from excel within certain range?
hi all, i am having an application where i am reading data from an excel sheet. in my case i am taking the date as an input from the user in range i.e starting date and end date in dd-mm-yy format( or to to from)and then i have to read the data of all dates which come between given range by the user....
how can i do it????
can anyone help......
thanks in advance.........Did you get the solution for your question ?
I have the same requirement,
1. Here, the user will provide the range like maximum and minimum values, then the VI should capture the data within the given range. ( from CSV file as attached )
2. Then VI should calcluate the average value for captured data and export it to excel.
This is my requirement can anyone help me on this.
Many thanks in advance
rc_cks
Attachments:
sample_short.csv 2439 KB -
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 PMDear 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 -
Formula to return text answer from a date cell that falls within a certain date range
I have a cell, lets say B2 which has a date eg/ 21JUN14. I want to return which season this falls into eg "low", "shoulder", "peak" etc from 5 specified date ranges. thanks.
HI KJ,
Here's the syntax for VLOOKUP, taken from the Numbers Help files:
VLOOKUP(search-for,search-range,return-column,close-match)
Your assumption regarding the 2 is correct.
The other key value is Wayne's omission of the fourth argument, "close-match". When omitted, VLOOKUP will look for an exact match, but will accept a close match, defined as 'the largest value less than (or equal to) search-value.
close-match is the reason the table needs to include only the first date of each season, sometimes referred to as the 'threshold value'. Any date 'larger' than that, but less than the next season's starting date will be accepted as being in that particular season.
Note that the searched for dates include the year. The Seasons table will need to be updated regulrly. If you know the starting dates for more than one year, all can be entered as soon as they are known. The table will handle as many dates as are currently known (within a limit that's in the tens of thousands).
Regards,
Barry -
To check a date lies within in a range
hi,
i need a fm to check whether a date lies within a range ( eq 30.04.2007) it lies between 16.04.2007 and 30.04.2004 (inclusive).hi,
Use the statement..
data : l_date type sy-datum value '20070430'
data : l_date1 type sy-datum value '20070416'
data : l_date2 type sy-datum value '20070430'
IF l_date BETWEEN l_date1 AND l_date2.
* Do the required Processing
ENDIF.
OR
Build the range
RANGES : R_date for sy-datum.
r_date-sign = 'I'.
r_date-option = 'BT'.
r_date-low = l_date1 .
r_date-high = l_date2.
append r_date.
IF l_date IN r_date.
* Do the required Processing
endif. -
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,
Hariif 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
Maybe you are looking for
-
ExportDataObject fails: "invalid action object"
Simple operation: I have a help file attached to the main PDF form. All I want to do is open it once upon opening of the form. I call the below function from the init procedure in the main form, but it fails. What am I doing wrong ? The file name is
-
Focus points are clustered in the center causing constant "focus & recompose"
It would be helpful is there were some outer focus points, I am constantly focusing and recomposing. Not so much an issue when handheld but a major obstacle when on a tripod.
-
Make a contact form information secure
I use Dreamweaver CC and Business Catalyst. I want to make sure that the infomation people send to me in my contact forms is secure! Does anyone have any advise for me on the best way to do this? Thanks
-
Oracle Apps 11i: Output Post Manager is down
Hi Experts, I was working on Oracle application cloning 11i lately and after completing the clone, my conc. manager output post manager (OPP) is not coming up in target system. I tried to fix the issue by running "cmclean.sql" and thn ran autoconfig
-
How to simplify/speed up Adobe reader
Ever since updating Adobe reader is less functional, takes too long to attach a document or crashes It's easier to save the document open my email program and select insert and browse to it...... Opening a PDF and printing it take forever now. Why, w