jquery - Get a previous date based on a future date using Javascript -


ideally take input field attach datepicker have pick future date in time example. [today 08/09/2013 @ time of writing , 07/31/2013 in return.]

i want no matter date picked, input field using javascript, default value wednesday prior week in-which initial selected date value.

function getwednesday(date) {     var d = (date.getday() == 0 ? 6 : date.getday() - 3);     date.settime(date.gettime() - (d * 24 * 60 * 60 * 1000));     return date; } 

this return wednesday of current week. understanding of javascript functions getday return 0-6 representing sun-sat. settime function takes string of milliseconds since january 1, 1970 , convert actual date in time , gettime exact opposite. i'm not sure im taking right approch have solid solution problem. in advance help

ok, here's clever way can think of:

function prevwed(indate){   var adder=(3-indate.getday());   var d=new date(indate.getfullyear(), indate.getmonth(), indate.getdate() + adder - 7);   return d } 

even smaller:

return new date(indate.getfullyear(), indate.getmonth(), indate.getdate() + (3-indate.getday()) - 7); 

will work?


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -