date field calculation

KNIME can calculate the difference between 2 date fields....

...and is there also a way to calculate the date if you have 1 date and the days?

e.g. 27 october 2010 + 230 days = [date].

henk

Hi Henk,

unfortunately there exists no such functionality yet. As a workaround you could use the Java Snippet node to do the calculation, return the result as String and use the "String To Date/Time" node to parse the results.  I know that this is kind of cumbersome but I have no better idea right now.

Dominik

Hi Dominik,

the cumbersome part is no problem, i'll find my way out.

my only problem is that i have no idea what to put in the java snippet. i have tried in all my innocence something like "$date end+10" but KNIME was not happy with that. do you have any idea how to do this?

Henk

Hi Henk,

in the Java Snippet node the datetime comes in as String. You could try something like this:

String pattern = "yyyy-MM-dd'T'HH:mm:ss";
java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat(pattern);
try {
	java.util.Date date = dateFormat.parse($Date and time$);
java.util.GregorianCalendar cal = new GregorianCalendar(
 		java.util.TimeZone.getTimeZone("UTC"));
     cal.setTime(date);
     cal.add(Calendar.DAY_OF_MONTH, 32);
     cal.add(Calendar.HOUR_OF_DAY, 14);
	return dateFormat.format(cal.getTime());
} catch (ParseException e) {
	return "Unparsable date: " + $Date and time$;
}

Then you can parse the calculated String.

Hope that helps,
Dominik

Hi Guys and ladies!!!

I tried something about it and using knime 4.6, I found a solution… You’ll use some components:

- “Date&Time Input”: to calc the “today” information automatically;

- “Variables to table row”: to set variable “DT_HOJE” as a table row to input the date;

- “String to Date&Time”: to convert the string information at the table row as a date information;

- “Date&Time Shift”: to go ahead or back on time;

If you use “-” symbol at the number field, it’ll call the difference before!

I made a simple sequence to have 2 dates (today as “DT_HOJE” and 6 month earlier as “DT_INICIO”), and the result were:

Workflow

image

Result

image

Thanks for your time!!! Like if you love this solution!