Difference

diff 1.4.0+

Get the difference between two dates.

                
let p = new PersianDate("1400/2/1","j")

p.diff("1400/1/1", "month"); // 1

p.diff("1400/1/1", "date"); // 31

p.calendar("gregorian").parse("2020-2-1");

p.diff("2020-1-1", "month"); // 1

p.diff("2020-1-1", "date"); // 31
                
        

1. You can pass the PersianDate instance, String, Array, Object and Date instance to the first argument

2. If null or undefined send to the first argument, this date compares with now

3. The second argument values is: [ 'y', 'year', 'years' ], [ 'M', 'month', 'months' ], [ 'd', 'date', 'day' ,'days' ], [ 'h', 'hour', 'hours' ], [ 'm', 'minute', 'minutes' ], [ 's', 'second', 'seconds' ] and [ 'ms', 'millisecond', 'milliseconds' ]

If the second argument equal to true, include the date itself.

                
let p = new PersianDate("1400/1/2","j")

p.diff("1400/1/1", "date"); // 1

p.diff("1400/1/1", "date", true); // 2
                
        

diffForHumans 2.0.0+

Get the difference between two dates in a human-readable format.

                
let p = new PersianDate("1400/1/1","j")

p.diffForHumans('1400/1/15'); // 14 روز پیش 

p.diffForHumans('1399/12/15'); // 16 روز آینده

p.diffForHumans('1400/1/1'); // هم اکنون
                
        

Like diff method:

1. You can pass the PersianDate instance, String, Array, Object and Date instance to the first argument

2. If null or undefined send to the first argument, this date compares with now

If the second argument equal to false, the suffix will be removed.

                
p.diffForHumans('1350/1/1', false); // 50 سال

p.diffForHumans('1450/1/1', false); // 50 سال