What I am trying is What I am trying to do is
Input Date : eg 5/8/2016 (2 months back from today's date) Current Date : eg 5/10/2016
I want to save the date difference between these 2 dates (Input Date - Current Date)
Later I want to Add this difference in dates to Current Date , and display the Input Date as it is.
Input Date can be any date behind from current date or future date
I am trying to use moment.Duration but it is giving me wrong output dates (always difference of 2/3 days added to current date)
Implementing functionality of relative date
Current date eg : 30/9/2016 Input date eg : 30/1/2016
I want to save the Difference between these 2 dates in DB (in ISO 8601 format duration UTC Value "-P8M4DT5.61S")
var actualDate = moment("30/1/2016");
var nowUtc = moment().utc();
var diff = actualDate.diff(nowUtc);
var duration = moment.duration(diff);
var savedDate= JSON.stringify(duration);
Here diff value which I am getting is wrong. Is there any issue in moment.js ?
later I parse the saved date and then try to add the Diff to current date which results is wrong calculation
var diffValue = JSON.parse(savedDate);
var durationVal = moment.duration(diffValue);
var nowUtc = moment.utc();
var originalDate = nowUtc.add(durationVal);
This 'originalDate ' I am getting should be 30/1/2016 but it always comes wrong
Can any one Help here ?
How to Save Date Difference In DB ? (in ISO 8601 format duration UTC Value) Then using the difference value retrieve date