Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subtracting hours from current date 1

Status
Not open for further replies.

vaks009

Programmer
Jun 14, 2001
11
CA
Hi Gurus:
I am new to javascript. Please help me in writing a javascript that will subtract x number of hours from current date.
thanks,
vaks
 
you can do this :

Date.prototype.substractHours = function (hours)
{
this.setTime(this.getTime() - (hours * 60 * 60 * 1000))
}

Then you have a date and can do :

var now = new Date()
alert(now)
now.substractHours(3)
alert(now)

I hope this helps. Gary Haran
 
Thanks a lot xutopia. As i mentioned i am fairly new to java world.
I am in jsp page so how do i implement above mentioned solution.
thanks again,
vaks
 
Got that Guru. Its all working now. Thanks a lot.
-vaks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top