Page 1 of 1

Add +1 day to [Switch.date]?

Posted: Wed Jun 18, 2014 5:05 pm
by lovestjarna
Is it possible to add -/+ to Switch date variable?

I want to compare to my tomorrow date, and not the present that is stated.

Ive tried:

[Switch.date]+1d

[Switch.date]+86400000

Including format and timezone it should look like this (but then also adding 1 day if possible)

[Switch.Date:Format="yyyy-MM-dd hh:mm",TimeZone=System]





The incoming xml have the date entered like this "201406191600", using the metadata and "date" doesn't work and gives me no value, if I change the date in the xml to "2014-06-18T16:20:38.483" it works...

Is it possible to change this in switch or to scheme it to work? I really would like to do this without scripting (if possible) and now change the xml (it comes from third part).

Add +1 day to [Switch.date]?

Posted: Wed Jun 18, 2014 5:39 pm
by freddyp
There are three things you have to combine and experiment with, but it can be done without scripting.



First, when using Switch-Date use the Format field to get the date in the form you need: yyyyMMdd will give you 20140619 instead of the full date and time (look at the tooltip!).



Second, use Switch-Calculation to add 1 to this number.



Third, you will have to put the recalculated date and the not recalculated time (Format: hhmm) together when comparing with the XML value.



I have not worked it out completely, but I am sure these hints can lead to a solution.



Freddy

Add +1 day to [Switch.date]?

Posted: Wed Jun 18, 2014 6:46 pm
by dkelly
First, when using Switch-Date use the Format field to get the date in the form you need: yyyyMMdd will give you 20140619 instead of the full date and time (look at the tooltip!).



Second, use Switch-Calculation to add 1 to this number.


This will fail for the last day of a month or year

Add +1 day to [Switch.date]?

Posted: Wed Jun 18, 2014 9:53 pm
by dkelly
So are you using [Switch.date] variable or a date read from an XML file?



Add +1 day to [Switch.date]?

Posted: Wed Jun 18, 2014 9:57 pm
by freddyp
Correct. Checking this on connections to make different calculations depending on the day and month is technically possible, but it is going to create a nice spaghetti flow. This calls for a script expression.



Freddy

Add +1 day to [Switch.date]?

Posted: Wed Jun 18, 2014 10:56 pm
by dkelly
const milliSecsInDay = 86400000;

var tmwMilliSecs = new Date().getTime() + milliSecsInDay;

var tmw = new Date(tmwMilliSecs);

tmw.toString();

Add +1 day to [Switch.date]?

Posted: Thu Jun 19, 2014 12:50 am
by lovestjarna
@dkelly Im reading from an xml file. So the "format" doesnt do anything with the input, only the output. Changing the date to the common "8601" makes the date work. I was hoping to be able to NOT change the date asking third part company to change their files.



The code putted in here above, should that then be used in the "define condition", comparing that to the metadata "date"?

Add +1 day to [Switch.date]?

Posted: Thu Jun 19, 2014 3:56 pm
by dkelly
That code is a script expression and outputs the current date/time + 24 hours. You can use it in a comparison