I have a date in a column that is of the format 2019-07-16 and need to update the date by 10 days. And it needs to the do the same to all the cell values in the column. Is there a node to do this ? or are there other ways to do this (Java snippet)?
First, I will have to check the value of a column. and if that check yields a value of TRUE then I have to increment the date column by 10 days else I have increment the value by 14 days.
I have tried a Java snippet with the following code in it but no luck.
// Your custom imports:
import java.io.StringReader;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
// system variables
public class JSnippet extends AbstractJSnippet {
// Fields for input columns
/** Input column: “VEHICLE UNIT DESC” /
public String c_VEHICLEUNITDESC;
/* Input column: “Day of Month of Last_IGN” /
public Integer c_DayofMonthofLast_IGN;
/* Input column: “LAST IGN DATE_Arr[0]” */
public LocalDate c_LASTIGNDATE_Arr0;
// Fields for output columns
/** Output column: “Days_Till_Dormant” */
public LocalDate out_Days_Till_Dormant;
// Your custom variables:
public String UnitGen;
public boolean isFound;
// expression start
public void snippet() throws TypeException, ColumnException, Abort {
// Enter your code here:
UnitGen = c_VEHICLEUNITDESC;
DateFormat dateFormat = new SimpleDateFormat (“yyyy-MM-dd”);
Calendar cal= c_LASTIGNDATE_Arr0;
if(isFound=UnitGen.contains(“GEN 10”) == true)
{
out_Days_Till_Dormant =c_LASTIGNDATE_Arr0.add(Calendar.DATE,10);
}
Check out our page on the Hub about the Column Expressions node. That node has its own extension that you’ll need to download, as @izaychik63 mentioned. If you drag the node from the Hub page into your KNIME workflow, you’ll be prompted to download and install that extension. Then you just need to restart KNIME, and the node should be available to you.
We’ve been trying to make the extension installation process more user friendly, so feedback is welcome!
@ScottF and @izaychik63 Thank you for your suggestions. I was able to find and install the node.
I was able to get to this point
a=column(“Gen Version”)
If (a = 11)
{column(“LAST IGN DATE_Arr[0]”)(Date,14)}
else
{column(“LAST IGN DATE_Arr[0]”)(Date, 10)};
But the node is telling me that it expects a operand in place of the else condition.
not sure what’s wrong here.
@armingrudd thanks for helping. But there seems to be something that I am doing wrong. (a == 11) did not work. I got a null pointer exception.
So I have a column called Gen Version. If the value in that column is 11 then I want to take the date in column called “Date of last IGN” and increase it by 14. Else Increase it by 10.
This is what I tried. (Did not work. )
a=column(“Gen Version”)
if (a ==11)
{column(“Date of last IGN”)(Date,14)}
else
{column(“Date of last IGN”)(Date,10)}
I have not worked with this function and also do not know what actually is going on here, but if the date column is “Date of last IGN” then the expression should be like this:
a=column(“Gen Version”)
if (a ==11)
plusTemporal(column("Date of last IGN"), periodOfDays(14))
else
plusTemporal(column("Date of last IGN"), periodOfDays(10))
Edited: Dear @Adiwakar, you have to use the plusTemporal and also convert the number to a period object. The expression above now works fine. It is just an example, you may need to change the numbers to get your desired output.
I would use more KNIME approach in this matter cause there is Date&Time Shift node which does exactly this. All you need is a Rule Engine node with your logic that will create new column containing 14 or 10 after which you can apply above mentioned node.