Hi, I'm getting a date from a customer formatted with [weeknumber] (week of the year) and then [weekdaynumber] and want to convert it to european date format: dd-mm-yyyy
Example 1:
Input value: 07-5
Wanted result: 19-02-2021
Example 2:
Input value: 20-1
Wanted result: 17-05-2021
The input value is meta data from an XML inject with XML Pickup.
Any suggestions how I can do the conversion?
Calculate date from [weeknumber]-[weekdaynumber]?
- magnussandstrom
- Advanced member
- Posts: 365
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact:
Re: Calculate date from [weeknumber]-[weekdaynumber]?
You will have to use a script to do that. There is a package for NodeJS called moment that will do that. This is more or less what it could look like (NOT TESTED!).
Without the locale settings the output is 12-02-2021 and not 19-02-2021.
Code: Select all
const moment = require("moment");
async function jobArrived(s, flowElement, job) {
moment.updateLocale("en", {
week: {
dow: 1, // First day of week is Monday
doy: 4, // First week of year must contain 4 January (7 + 1 - 4)
},
});
let dayOfWeeek = await flowElement.getPropertyStringValue("DayOfWeek").toString();
let weekOfYear = await flowElement.getPropertyStringValue("WeekOfYear").toString();
let date = moment().day(dayOfWeek).week(weekOfYear);
let DDMMYYYY = date.format("DD-MM-YYYY");
await job.setPrivateData("DDMMYY", DDMMYY);
await job.sendToSingle();
}
Re: Calculate date from [weeknumber]-[weekdaynumber]?
It can be even simpler
In this case the 05 and 4 will be replaced by variables or maybe just one variable for the 05-4
Code: Select all
const moment = require("moment");
var myDay = moment("2021-W05-4").format("YYYY-MM-DD");
console.log(myDay);
- magnussandstrom
- Advanced member
- Posts: 365
- Joined: Thu Jul 30, 2020 6:34 pm
- Location: Sweden
- Contact: