Comparing 2 dates and putting results in predetermined buckets
Hi all
I want to write a method which takes in as parameters 2 date objects. It works out the difference (number of years) between the 2 dates and depending on this the results are flagged against 1 of 5 buckets.
Each bucket represents the following number of years 2, 5, 10, 20 and 30. So if my first 2 dates are taken and the number of years is 23 then the date should be stored against the 20 year bucket, or if the number of years is 6 then the date should be stored against the 5 year bucket, a value of 16 would be stored in the 20 year bucket etc...
I was looking for suggestions on the neatest way of doing this - any suggestions would be appreciated.
Sorry my original post wasnt to clear.
When 2 dates are compared and the result is given e.g. 22 years - I need to add the second of the 2 dates to a container of some sort which represents 20 year things. So if the 2 dates are 01-Jan-2000 and 01-Jan-2022 then I would work out the difference in years which is 22 in this case, then the second date would be allocated to a bucket (an object which I havent decided on yet - e.g. could be a List or anything else) which hold dates which are closest to 20 years.
As in this example the difference is 22 years (not exactly 20) the logic would allocate the date to the 20 year bucket as 22 is closer to any of the other buckets:
2, 5, 10, 20 and 30. So I guess part of the logic is getting the difference in years e.g. 22 and then working out which of the 5 buckets this falls into.
I hope that makes it clearer - thanks again.
Similar Messages
-
How to compare date and time together
Hi,
How to compare Date and Time together?
For example in a database table there are two fields rundate and runtime. I want to compare these two with perticular date and time in the program. Like, I want to pull all the records where the records's date and time are less than a perticular date and time in the program.
Hope the question is clear...
Thanks.
KavitaHi Kavita
There is no as such Date and Time Comparision FM in Standard SAP But You can define your own like this
<b>FUNCTION ZAV4_COMPAREDATETIME.
""Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(DATE1) TYPE DATS
*" REFERENCE(TIME1) TYPE TIMS
*" REFERENCE(DATE2) TYPE DATS
*" REFERENCE(TIME2) TYPE TIMS
*" EXPORTING
*" VALUE(TWOISMORETOPICAL) TYPE C
twoismoretopical = ''.
if date2 > date1.
twoismoretopical = 'X'.
else.
if date2 = date1 and time2 > time1.
twoismoretopical = 'X'.
endif.
endif.
ENDFUNCTION.</b>
Regards
Mithlesh -
Function module for comparing dates and times
Hi,
I have a date and time stamp in one filed for example as below:
20070125183045
(the first 8 are date in YYYYMMDD format, the next 6 is time in HHMMSS format). Now I want to compare this value to another such value in terms of date and time. First I want to compare dates and then times. Do you know any function module that can serve this purpose?
Thanks very much!You can compare these using the function module DURATION_DETERMINE. This fuction will give you the difference, and it can be in a view different units, such as the difference in days, months, etc.
Funciton module takes in Start date and time and end date and time.
Regards,
RIch HEilman -
I need an ethernet cable connection to a non-wireless device that isn't near my current airport express. Can I buy an extra one to plug in near the non wireless device to receive the wireless data and put the signal out in ethernet form?
Yes, you can.
This is a special feature of the AirPort Express 802.11n. You will have to set it up "manually" to "enable Ethernet clients".
If your "main" AirPort Express is an 802.11n version, it is also possible to setup the second Express to "extend a wireless network" to provide additional wireless coverage in addtion to enabling the Ethernet port.
If you need the steps, post back to let us know what operating system you are using on the Mac or PC that will be used for the setup of the new AirPort Express. -
Compare Dates and select the max date ?
Hello,
I am trying to write a script and will compare the dates in " eff_startdt" and give me the lastest date at the outcome.
I have data that some service locations have more than one contract date and I need to get the latest dated conract dates to work on the data but I tried many things I am always getting errors. When I run the script below I get " missing expression" error. I dont' see anything missing.
also somehow Max() is keep giving me errors when I do something like [ ON service_locs = vmeterid WHERE SERVICE_LOCS = SERVICE_LOCS AND EFF_STARTDT = MAX(EFF_STARTDT) ]
Can someone pls give me advice on this. Thanks
SELECT DISTINCT Broker, customer_name, service_locs, fee_kwh, qtr_monthly, eff_startdt, eff_enddt
FROM VMETER
INNER JOIN BROKER_DATA
ON service_locs = vmeterid WHERE SERVICE_LOCS = SERVICE_LOCS AND (SELECT MAX(EFF_STARTDT) FROM VMETER)
-----------------------------------------------------------Hi,
I will try to explain on my example. I have got a table:
DESC SOLD_ITEMS;
Name Value NULL? Type
COMPONENT VARCHAR2(255)
SUBCOMPONENT VARCHAR2(255)
YEAR NUMBER(4)
MONTH NUMBER(2)
DAY NUMBER(2)
DEFECTS NUMBER(10)
DESCRIPTION VARCHAR2(200)
SALE_DATE DATE
COMP_ID NUMBERI have insert example data into my table:
select component, subcomponent, sale_date,comp_id
2 from sold_items;
COMPONENT SUBCOMPONENT SALE_DAT COMP_ID
graph bar 06/04/03 1
graph bar 06/04/01 2
search user search 06/04/02 3
search user search 06/04/01 4
search product search 06/03/20 5
search product search 06/03/16 6
graph bar 06/05/01 7
graph bar 06/05/02 8
graph bar 06/05/02 9
As you can see there are a few components and subcomponents duplicated with different date and comp_id value.
I want to get component and subcomponent combination with latest date.
SELECT COMPONENT, SUBCOMPONENT, MAX(SALE_DATE)
2 FROM SOLD_ITEMS
3* GROUP BY COMPONENT, SUBCOMPONENT;
Efect:
COMPONENT SUBCOMPONENT MAX(SALE
graph bar 06/05/02
search user search 06/04/02
search product search 06/03/20
For your purpose I will do it using join and subquery. Maybe it will help you resolve your problem:
SELECT COMPONENT, SUBCOMPONENT, SALE_DATE, RANK
2 FROM (SELECT T1.COMPONENT, T1.SUBCOMPONENT, T2.SALE_DATE,
3 ROW_NUMBER() OVER (PARTITION BY T1.COMPONENT, T2.SUBCOMPONENT ORDER BY T2.SALE_DATE DESC) AS ROW
4 FROM SOLD_ITEMS T1, SOLD_ITEMS T2
5 WHERE T1.COMP_ID = T2.COMP_ID)
6* WHERE ROW = 1;
I joined the same table but it act as two different tables inside subquery. It will group values (partition by statement) and order result descending using t2.sale_date column. As you can see columns are returned from both tables. If you would like to add some conditions, you can do it after WHERE ROW=1 code.
Results:
COMPONENT SUBCOMPONENT SALE_DAT RANK
graph bar 06/05/02 1
search product search 06/03/20 1
search user search 06/04/02 1Hope this help you
Peter D. -
Case statement to compare date and then count duration from only one date
Hi All;
I need to compare two dates and if date 1 > date 2 then consider date 2 and count its duration of appointments from date 2
case when CTE.scheduledstart between [dbo].[DateTimeConvert] (new_dateofapplication) and
[dbo].[DateTimeConvert](ac.new_businessstartdate)
then
(CTE.scheduleddurationminutes)
when ( [dbo].[DateTimeConvert] (new_dateofapplication) > [dbo].[DateTimeConvert](ac.new_businessstartdate))
then
[dbo].[DateTimeConvert](ac.new_businessstartdate)
end as 'AFTERAPP',
Any help on this is much appreciated
I need to use case statement fro this
Thanks
Pradnya07when you say list of Appointments from Appointments table calculate duration from this date [dbo].[DateTimeConvert]
do you mean find out duration from multiple record? or do you want
suration for each row? also what represents this date here? Is it new_dateofapplication?
can you show expected result for the data posted above?
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Need help in using SQL in a jsp file to compare date and time
hi every one,
Actually I am doing a project using JSP. I need to compare a date field in the database (MS Acess) to the current system date and time. I have to do this in a select statement.
I have alredy defined a variable of type Date in the JSP file and I am comparing this variable to the date in the database through a select statemant.
Here is what I am doing
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
java.util.Date today = new java.util.Date();
String myDate=sdf.format(today);
query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= "+myDate+" ;";
EDate is the feild in the database and it's format is (5/12/2008 5:29:47 PM) it is of type Date/Time in MS Acess.
when I execute the query it gives the following error
SQL error:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'EDate <= 2008-10-16 08:10:07'.
I hope any one can help me with that error and answer my question, I've tried too many things but nothing helps
Thanks in advance :-)Hi,
When the comparision is needed to be done with the current date , we don't need to send in Java
Date then format it and compare with MS Acess Date.
In MS Access we have Date() function which will give you the current date.
So you can try rewriting your query as following :
query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= Date() ;"; ---------------------
Hope this helps.
Thanks -
Formula for comparing dates and display data
I have 3 objects on my query: Date, Product name and Quantity sold
I have a table on my reports showing the top 3 products by quantity sold, and I want to add the quantity sold today on the same table.
I am looking for a formula that compares de dates provided by the query with current date and only displays on the cell the quantity for the current day.
Any ideas are welcome!As per my understanding, you want to display the today's sale of the product while the ranking is aaplied on the total quantity
sold.
You can create a new variable with either of the following two definitions:
Today's Date = CurrentDate()
Today's Sale = Sum([Quantity Sold]) where ([Date]=[Today's Date])
or
Today's Sale = If(([Date]=[Today's Date]) Then Sum([Quantity Sold])
Note: The two date formats should be same.
For getting the top three products you can use the hidden column(font, border and background white) and apply the ranking on
the total sale coming from the DB.
Regards,
Rohit -
Substacting two dates and get result in months
Hi Friends
I have to subtract two dates and get the difference in months. Here's the sample data:
select DATE '2009-10-01' Date_value, 111 Cust_id, DATE '2009-10-22' Open_date from dual
union all
select DATE '2009-10-01', 112 , DATE '2009-10-15' from dual
union all
select DATE '2009-10-01', 113 , DATE '2009-10-5' from dual
union all
select DATE '2009-11-01', 111 , DATE '2009-10-22' from dual
union all
select DATE '2009-11-01', 112 ,DATE '2009-10-15' from dual
union all
select DATE '2009-11-01', 113 ,DATE '2009-10-22' from dualAnd here’s my query to get the difference in month:
SELECT cust_id, date_value, open_date,
ROUND (ABS (date_value - open_date) / 365 * 12) diff_in_months
FROM tBut the output is unexpected:
CUST_ID DATE_VALUE OPEN_DATE DIFF_IN_MONTHS
111 1/10/2009 22/10/2009 1
112 1/10/2009 15/10/2009 0
113 1/10/2009 5/10/2009 0
111 1/11/2009 22/10/2009 0
112 1/11/2009 15/10/2009 1
113 1/11/2009 22/10/2009 0Ideally, the output should be as per the following:
CUST_ID DATE_VALUE OPEN_DATE DIFF_IN_MONTHS
111 1/10/2009 22/10/2009 0
112 1/10/2009 15/10/2009 0
113 1/10/2009 5/10/2009 0
111 1/11/2009 22/10/2009 1
112 1/11/2009 15/10/2009 1
113 1/11/2009 22/10/2009 1What is wrong in my query?Hi Centinul
Found the resolution. When I use the following query, I get the perfect result:
SELECT cust_id, date_value, open_date,
ROUND (ABS (MONTHS_BETWEEN (open_date, date_value))) months,
ROUND (ABS (date_value - open_date) / 365 * 12) diff_in_months,
MONTHS_BETWEEN (date_value,ADD_MONTHS (LAST_DAY (open_date), -1) + 1 ) final_val
FROM tAnd here's the output of all three columns:
CUST_ID DATE_VALUE OPEN_DATE MONTHS DIFF_IN_MONTHS FINAL_VAL
111 1/10/2009 22/10/2009 1 1 0
112 1/10/2009 15/10/2009 0 0 0
113 1/10/2009 5/10/2009 0 0 0
111 1/11/2009 22/10/2009 0 0 1
112 1/11/2009 15/10/2009 1 1 1
113 1/11/2009 22/10/2009 0 0 1 -
How to take waveform chart data and put it into an array
Hello all,
I am new to programming in Labview, and am learning basically by watching youtube video and such. My question is how to take a set of random data that I have written code for and linked to a waveform chart, and put the data into an array so I can calculate the mean of the data set. If there is an easier way to calculate the mean of the data set I am all ears, but I need to be able to display the mean on the front panel each time the code is run. I have attached a file of my code.
Thanks
Attachments:
CA1.vi 11 KBWelcome.
If you have not done so, look at the on-line tutorials on Getting Started with LabVIEW on the NI web site.
A chart has a property known as History which retains some previous values. You can get access to the the History property by popping up on the block diagram terminal of the chart and selecting Create >> Property Node. Note that the history length can be set via a pop up menu. The default length is 1024.
Other comments: When you know the number of iteration in advance you should use a for loop rather than the while loop.
You can also use an autoindexing tunnel at the boundary of the loop to create an array. It only contains the values from the current run, unlike the chart history which can retain values between runs (as long as the VI remains in memory). Watch the two Mean indicators as you run this VI several times.
The error wire is to assure that the history property node runs after the loop. Disconnect the wire and watch the Mean and Mean 2 indicators carefully.
The Wait is to slow things down a bit so that you can see what is happening.
Lynn
Attachments:
CA1.2.vi 11 KB -
SQL statement to compare dates and return boolean (yes/no)
I am looking for a SQL statement that can compare 2 dates and return a boolean. 1 (yes) if date 1 is => date2-threshold or 0 (No) if date < date2-threshold
Ie
date1=20130603
threshold=2 days
date2=sysdate-threshold
if [ 20130603 > sysdate-$threshold ]
then
return 1
else
return 0
fi
Thanks to all that answer.Assumming I want to get "date1" from some other table instead of from
dual will this syntax be valid
I was going to invoke another SQLPLUS from my shell script and pass it in
as a variable but if I can do it on one shot it would be better.
In addition, if "no rows" are found for date1 from the below query, would
I need code to handle that
with xx as
select TO_DATE(last_date','yyyymmdd') date1, from dba_audit_table where ...;
select TO_DATE('20130603','yyyymmdd') date1, sysdate date2 from dual;
Thanks to all who answer
[/code1] -
SQL Where clause when comparing dates and times in ASP
Hello,
I am trying to pull data from my database which is dependant on both the date and time in HH24 format. So, my where clause looks something like this:
select * from thisTable where activity_time >= myCurrentDate
(myCurrentDate is a variable that is built which gives it the following format DD-MON-YYYY HH24:MI:SS)
So, the actual passed string to my call is:
select * from thisTable where ACTIVITY_TIME >= '02-DEC-2008 18:22:00' order by ACTIVITY_TIME asc
However, when calling this, I get the famous "ORA-01830: date format picture ends before converting entire input string"
Can anyone please help me?!?!?!?
Thanks in advanceEnrique answered your immediate question, but I'd like to point up a broader issue, and that is that you should <b><u>always</u></b> use the TO_DATE and TO_CHAR functions at the sql statement level when working with date datatypes. That way you are never dependent on some default over which you have no control. I call that is 'defensive coding'.
-
Commit data and put it to database
Hi,
Anyone know how to put data from objects to database table?
Now I have a simple application which get data from table, modify some rows and now I don't know how to put this result to another table in database.
Thanks for any suggestions.
I have to add, that I put data from database, modify it, and insert new row to another database (anoteher phisical machines). So probably I need to create 2 connections. But do I need mapping table to objects in second database if tables are similar in both of this databases??
Message was edited by:
tutusWhat version of TopLink are you using? Are you using JPA? I'll assume EclipseLink JPA.
The easiest thing to do is to create two persistence units (PU), one for each database schema. Using orm.xml mapping you can map the same class to both the source and target table. If the tables are pretty similar you could map the common mappings with annotations and use xml to map the things that are different.
Using this approach you can read an object from the source PU, modify it and then persist it in the second PU.
--Shaun -
Compare data and return the different columns
Good Afternoon,
I am trying to compare the data in two tables and return only the columns and data where there is a difference.
I have a compare script which checks every column in the two tables against each other, but as there are 200 columns in the tables it is tricky to see which column has a difference.
So in my result set if coulum N is the differenct I would only want to return column N from both tables in the result set.
I hope that this all makes sense?.Easiest way is to use tablediff utility for checking difference between tables
see
http://www.mssqltips.com/sqlservertip/1073/sql-server-tablediff-command-line-utility/
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Retrieve 3 rows of data and put each row in different position on screen
I need to retrieve 3 consecutive rows of data (easy) and need to put each row's data in an entirely different location on the home page
for example,
row 1 needs to go up in the top left content box
row 2 needs to go in the large content area in the middle of the page
row 3 needs to be put down in the footer of the page
what's the most efficient way to do this ?Ok, I've tried to research this a bit more, but I'm no further forward
So if I have a query...
<cfquery name="getData" datasource="foo">
SELECT *
FROM 00_pricelist
</cfquery>
<cfoutput query="GetData" startrow=1 maxrows=3 >
<!--- surrounding table 1 --->
#getData.uneak_code[1]#<br />
<!--- surrounding table 2 --->
#getData.uneak_code[2]#<br />
<!--- surrounding table 3 --->
#getData.uneak_code[3]#<br />
</cfoutput>
can you tell me what I'm doing wrong ?
Maybe you are looking for
-
In need of a new Graphics/Video card,..which one?
My computer stopped booting all the way a couple of days ago. Took it to Apple store where they told me I need a new Graphics card. As of now I have: Chipset Model: NVIDIA GeForce 7300 GT Bus: PCIe PCIe Lane Width: x16 VRAM (Total): 256 MB Vendor: NV
-
I am trying to export a video as an flv but the list of possible formats is much shorter than it used to be. I cannot find any way to make an FLV using the newest version of Premiere Pro. Need help fast! I am on a Mac
-
How to send an attachment with adobe form
Hi in my application i have two process intiator and approval process both are adobe interactive forms,according to my scenarion i need to send an attachment(pdf or word document....)in intiatior to approval process,can pleasse tell me how to send th
-
Hi Friends, I have created a Hierarchy using Flat File. Every thing goes fine. But the hierarchy appears in grey colour instead of green. when i am trying to activate it manually, the program is terminating giving an error "Error while executing SQL
-
Hi all, I want to accept an event for the logged user, and i'm using the following string: MIME-Version: 1.0 Content-Type: text/calendar Content-Transfer-Encoding: quoted-printable BEGIN:VCALENDAR VERSION:2.0 PRODID://Oracle//CAPI//EN BEGIN:VEVENT CL