0

I want to get the difference between tow dates in javascript but my problem is that the first date is the currenet date of the PC :

today = new Date();

and the other date is a text format date like this for example:

other_date = '15.11.2013';

I want the today date to be same format as other_date and then subtract them , How can I change the format of the today to make the same as other_date ? and How I can make them both as date format to subtract them and get the difference correctly???

2

1 Answer 1

1

I would simply use the split function to get the date parts of the date string:

var today = new Date();
var other_date = '15.11.2013';
var dateparts = other_date.split('.');
var otherDate = new Date(dateparts[2], dateparts[1]-1, dateparts[0]); // substract 1 month because month starting with 0

var difference = today.getTime() - otherDate.getTime(); // difference in ms
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.