Calculate date difference in days

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Calculate date difference in days

vivek.mi
Hello everyone,

I want to calculate the difference in days between the now-timestamp and some previous date. How this can be achieved in XML or ftl.


Thanks in advance
Vivek Mishra
Vivek Mishra
Reply | Threaded
Open this post in threaded view
|

Re: Calculate date difference in days

Jad El Omeiri
Hi Vivek,

1)
If you want to do the calculation in XML (in screen widgets), I would suggest calling a java method like that:


<call-class-method class-name="org.ofbiz.base.util.UtilDateTime OR whatever class that contains the method" method-name="methodName" ret-field="resultVariable">
    <field field="date1" type="java.sql.Timestamp"/>
    <field field="date2" type="java.sql.Timestamp"/>
</call-class-method>

2)
If you want to do it in ftl, just subtract the 2 dates and divide by 1000*60*60*24. Make sure the dates are both correctly formatted.
Take a look at that:
http://stackoverflow.com/questions/11412040/how-do-i-calculate-the-difference-in-days-between-two-iso8601-dates-with-freemar

Hope that helps.

Cheers,
Jad El Omeiri
Reply | Threaded
Open this post in threaded view
|

Re: Calculate date difference in days

Adrian Crum-3
A better approach would be to use the org.ofbiz.base.util.TimeDuration
class.

The <call-class-method> element is deprecated.

Never use millisecond arithmetic.

Adrian Crum
Sandglass Software
www.sandglass-software.com

On 12/24/2014 2:58 PM, Jad El Omeiri wrote:

> Hi Vivek,
>
> 1)
> If you want to do the calculation in XML (in screen widgets), I would
> suggest calling a java method like that:
>
>
> <call-class-method class-name="org.ofbiz.base.util.UtilDateTime OR whatever
> class that contains the method" method-name="methodName"
> ret-field="resultVariable">
>      <field field="date1" type="java.sql.Timestamp"/>
>      <field field="date2" type="java.sql.Timestamp"/>
> </call-class-method>
>
> 2)
> If you want to do it in ftl, just subtract the 2 dates and divide by
> 1000*60*60*24. Make sure the dates are both correctly formatted.
> Take a look at that:
> http://stackoverflow.com/questions/11412040/how-do-i-calculate-the-difference-in-days-between-two-iso8601-dates-with-freemar
>
> Hope that helps.
>
> Cheers,
>
>
>
>
> -----
> Jad El Omeiri
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Calculate-date-difference-in-days-tp4660532p4660551.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Calculate date difference in days

Jad El Omeiri
Hi Adrian,

What would you use instead of <call-class-method> ?

Adrian Crum-3 wrote
A better approach would be to use the org.ofbiz.base.util.TimeDuration
class.

The <call-class-method> element is deprecated.

Never use millisecond arithmetic.

Adrian Crum
Sandglass Software
www.sandglass-software.com
Thanks,

Jad
Jad El Omeiri
Reply | Threaded
Open this post in threaded view
|

Re: Calculate date difference in days

Adrian Crum-3
<script>

https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=27840333

Adrian Crum
Sandglass Software
www.sandglass-software.com

On 12/24/2014 3:27 PM, Jad El Omeiri wrote:

> Hi Adrian,
>
> What would you use instead of <call-class-method> ?
>
>
> Adrian Crum-3 wrote
>> A better approach would be to use the org.ofbiz.base.util.TimeDuration
>> class.
>>
>> The
>> <call-class-method>
>>   element is deprecated.
>>
>> Never use millisecond arithmetic.
>>
>> Adrian Crum
>> Sandglass Software
>> www.sandglass-software.com
>
> Thanks,
>
> Jad
>
>
>
> -----
> Jad El Omeiri
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Calculate-date-difference-in-days-tp4660532p4660555.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.
>