on 07-04-2017 10:54 AM
Can anyone please help me to get duration between Given date and current date.
Example : If given date is 2012-03-29 then duration should be 5 Years and 3 months.
If given date is 2012-07-25 then duration should be 4 Years and 11months. I want to send these dates dynamically.
Thanks & Regards
Swetha
can you please let us know your PI version? If it is on 7.5, then it should be easier to achieve it.
Please check below stackoverflow thread
https://stackoverflow.com/a/1116138/4286953
https://stackoverflow.com/a/27738766/4286953
if you run this on java 8, you will get the same results.
LocalDate start = LocalDate.of(2012, 7, 25); //
LocalDate end = LocalDate.of(2017, 7, 04); //
long years = ChronoUnit.YEARS.between(start, end);
long months = ChronoUnit.MONTHS.between(start, end);
System.out.println("years " + years);
System.out.println("months " + months % 12);
Regars,
Muni
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check the java api
https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html
below two methods will do the job for you.
static LocalDateparse(CharSequence text)
static LocalDatenow()
String given_Date = "2012-07-25"; // pass the input to the UDF as string
LocalDate start = LocalDate.parse(given_Date); // to create LocalDate Obj
LocalDate end = LocalDate.now(); // get current date
System.out.println(end.getYear()+" "+end.getMonthValue()+" "+end.getDayOfMonth());
System.out.println(end.toString());
Results.
2017 7 5
2017-07-05
Similarly you can check the start date values also.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.