using jQuery 2 create 2 dates, 1 now in DD/MM/YYYY format, the 2nd same format but 180 days ago

Hi

This seems such an easy thing to do bit having difficulty finding an example.

using jQuery I want to create  2 dates, 1 now in DD/MM/YYYY format, the 2nd same format but 180 days ago and assign them to variable to be used later.

Need to take into account that for example on 30 Jan 2015 then -180 days would take it back to 2014 etc.

Thanks
Neil
LVL 3
Neil ThompsonSenior Systems DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
for this I would recommend the library moment.js
http://momentjs.com
There you can format the output as well as adding/subtracting days/months ...
HTH
Rainer
Rainer JeschorCommented:
Sample code:
$(document).ready(function () {
    var message = "Today is " + moment().format("DD/MM/YYYY");
    $("#message1").html(message);
    var message2 = "The date 180 days ago is " + moment().subtract(180, 'days').format("DD/MM/YYYY") ;

    $("#message2").html(message2);
});

Open in new window

Live sample:
http://jsfiddle.net/EE_RainerJ/n2mohbcd/

HTH
Rainer

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Thanks Rainer

Thats brilliant but the 2nd date is wrong for some reason, 01/12/2014

Should be around 30/02/2015

Any ideas?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

RobOwner (Aidellio)Commented:
180 days ago is December. That's half a year. 90 days would be February.
Neil ThompsonSenior Systems DeveloperAuthor Commented:
lol, embarrassingly dumb , apologies :)
RobOwner (Aidellio)Commented:
Nope, done it myself! *grin* you can look at days and numbers too long sometimes!

Btw don't give me any points if you were thinking along those lines... Rainer has more than answered your question without my help :)
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Many thanks all for your example and comments :) Saved me hours!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.