Talend Connect
Virtual Summit
JOIN US!
And visit the Customer
& Community Lounge.
May 27-28, wherever you are.

Average Date Between Two Given dates

Highlighted
Eight Stars

Average Date Between Two Given dates

hello everyone,

in my scenario i want to find average date between gives two dates ,

Date 1                date 2 

01-05-2002         03-09-2017

07-05-2001        05-02-2016

 

Thanks in advance,

Manish

 

Highlighted
Forteen Stars

Re: Average Date Between Two Given dates

  1. TalendDate.diffDate(myDate1,myDate2,"dd") - days between dates

  2. Numeric.random(0,TalendDate.diffDate(myDate1,myDate2,"dd")) - random from 1 to number of day between dates

  3. TalendDate.addDate(myDate1,Numeric.random(0,TalendDate.diffDate(myDate1,myDate2,"dd")),"dd") - add random days to begin date

so, final - TalendDate.addDate(myDate1,Numeric.random(0,TalendDate.diffDate(myDate1,myDate2,"dd")),"dd")

 

Upd

:-) , never answer at night 
sorry, read average as random, see answer from @tjclearner

-----------
Highlighted
Five Stars

Re: Average Date Between Two Given dates

Hi,
- First calculate days between the 2 dates then divide by 2 : TalendDate.diffDate(Date2, Date1, "dd")/2
- Then add the result to Date1
----------
Thanks ,
tjclearner

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog