I am new to freemarker.
In freemarker, I would like to perform arithmetic expression on DateTime as follows:
${triggerTimestamp}-1h
But this is not working. Could anyone please help here?
FreeMarker doesn't do date/time arithmetic out of the box (as of 2.3.30 at least). It's expected that the data-model (context) contains the values that you actually want to display. One can implement some helper method in Java though.
You'll want to explore converting the date into unix/epoch time. If you add ?long to the end of the variable you'll convert the datetime into epoch time (which is in seconds) then do math and convert it back to a date. Your example would be
${(triggerTimestamp?long - 1 * 1000 * 60 * 60)?number_to_datetime?string.iso}
Related
In business central there is this data type named DateFormula, in it you can define things like '1D + 2H + 3S' (1 day, 2 hours and 3 seconds). I found out that i can convert this time range to a Date using CalcDate() however, Date objects dont contain the time information, which I do need.
There is no CalcDateTime() function in BC, nor does it mention converting DateFormula's to DateTime anywhere online it seems.
How can I convert a DateFormula to a DateTime object in BC?
OK so apparently it turns out that DateFormula datatype does not even support things like hours and seconds, only dates and no times.
Solved!
Hello i've been working on how to get yesterday date in DataStage?
CurrentDate()-1
When i compile the job, it gave me an error.
So how should i do to get the yesterday date?
btw that code i'm doing it in the Transformer stage
Assuming you are using the parallel engine in DataStage - this could be a solution
DateOffsetByComponents
DateOffsetByComponents(CurrentDate(), 0, 0, -1)
As the last parameter is the day part and -1 would substract a day
Convert the date into a date type, then you can add or subtract days.
You can use IConv to convert a string into a datastage internal date format. Then you can perform addition/subtraction on the date. Then use OConv to convert the variable back to string format.
If this is done in a transformer stage, you need to do this all in one statement:
OConv(Iconv(VDate ,"D/YMD[4,2,2]") - 1), "D/YMD[4,2,2]")
Hope this helps.
In a parallel Transformer stage, I'd use DateFromDaysSince() function. Use current date function as the base, and -1 as the offset value.
Can someone please guide me on how to convert more than 6 characters into int? Because I need to do sum after convert to int. I tried so many ways like CInt, CLng, etc still throw exponential value.
Stroutput = 2018050302216556
Sum = Stroutput + 1
I tried to divide into sveral chuck using right function but it doesnt look good. Can be manage but I need another option. Thanks
You seem to be working with a Date Structure, which as VBS says - hard to represent as numbers only. Use the CDate to get a date object from the string (If needed change the representation of that string to (YYYY-mm-dd ...). With the DateAdd method you can add days, years etc; and finally the FormatDateTime will create an output of your wish.
Need to get difference between 2 dateTime payload objects as duration format for using on HT expiration value. (i.e. returned as PT2055M or P1DT10H15M)
Actually checked functions on that link: http://docs.oracle.com/cd/E23943_01/dev.1111/e10224/bp_appx_functs.htm#autoId13
And i tried to solve the issue by creating duration such as
concat("P", xp20:year-from-dateTime(string(bpmn:getDataObject('myPayloadDate'))) - xp20:year-from-dateTime(xp20:current-dateTime()) ,"Y", xp20:month-from-dateTime(string(bpmn:getDataObject('myPayloadDate'))) - xp20:month-from-dateTime(xp20:current-dateTime()),"M", xp20:day-from-dateTime(string(bpmn:getDataObject('myPayloadDate'))) - xp20:day-from-dateTime(xp20:current-dateTime()),"DT", xp20:hour-from-dateTime(string(bpmn:getDataObject('myPayloadDate'))) - xp20:hour-from-dateTime(xp20:current-dateTime()),"H",xp20:minute-from-dateTime(string(bpmn:getDataObject('myPayloadDate'))) - xp20:minute-from-dateTime(xp20:current-dateTime()),"M")
But realized that this approach interests with just only seperate values not whole values as expected.
I could not find the right composition of functions to solve.
Could you plz guide?
Assuming you have an XPath 2.0 processor, just use the subtraction operator. For example
current-date() - xs:date('2001-03-04')
gives
P4744D
(You said "dates" but your examples look more like dateTime's. The subtraction operator will work with either.)
XQuery offers various date/time functions like current-dateTime(), however I can't seem to find one which gives me the time in milliseconds since Epoch. Functions to extract hours, minutes and seconds seem to exist too individually.
What is the right way to get the Epoch time (i.e. unix time or similar) in XQuery?
(current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xs:dayTimeDuration('PT0.001S')
returns the number of seconds as a duration, and then divides by 1 millisecond to get the number of milliseconds as a number.
thank you for the tips. I modify the code for Oracle Service Bus 11g (OSB 11g) Xpath editor in case someone else needs it
{ (fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xdt:dayTimeDuration("PT0.001S") }
Additional tricks on Aditya's answer for OSB 11g.
There has an annoying bug on XQ Editors that will change div and operator into a , (comma).
Just put a conversion function in front of that code. such as xs:long, xs:string
ex.
{ xs:long((fn:current-dateTime() - xs:dateTime("1970-01-01T00:00:00-00:00")) div xdt:dayTimeDuration("PT0.001S")) }