04-21-2017 08:05 AM
I need to add “Day of the Year” as part of an output file-name. How can I do that?
04-21-2017 09:00 AM
@Abhijit, I believe I was able to do this using the following expression:
Math.ceil((($today - $jan1st) / 1000 / 60 / 60 / 24) + ((($jan1st.getTimezoneOffset() - $today.getTimezoneOffset())) / (60 * 24)))
For clarity, I’ve split it into to two Mappers using the Expression Language. The first creates Date objects for today and for January 1st. I then use these two variables in the following expression to calculate the day of the year.
It might be easier to see the formula in this format:
Math.ceil(
(
($today - $jan1st) / 1000 / 60 / 60 / 24
) + (
($jan1st.getTimezoneOffset() - $today.getTimezoneOffset()) / (60 * 24)
)
)
Pipeline: 20170421_day-of-year_2017_04_21.slp (3.5 KB)
I’m getting a current “day-of-year” value of 111, which matches the result from Epoch Converter:
Alternatively, this could all be done in a single expression:
Math.ceil(((Date.now() - Date.parse(Date.now().getFullYear() + "/1/1")) / 1000 / 60 / 60 / 24) + (((Date.parse(Date.now().getFullYear() + "/1/1").getTimezoneOffset() - Date.now().getTimezoneOffset())) / (60 * 24)))
04-21-2017 09:00 AM
In the file name field you can use an expression which looks something like:
"myfile" + Date.now().toLocaleDateTimeString('{"format":"DDD"}') + '.json'
04-21-2017 09:02 AM
Ah, @cstewart that’s much easier.
04-21-2017 01:27 PM
Actually, the following is more efficient:
"myfile" + Date.now().toLocaleDateTimeString({"format":"DDD"}) + '.json'
(Single quotes removed around the format…)