PDA

View Full Version : Add or subtract minutes/hours from Date object?


Roku
07-09-2008, 08:39 PM
How do I add minutes or hours to a Date object? For example, my application is kind of like an alarm clock with a "snooze" feature, and for the snooze time I need to add 15 minutes to the original time.

var now = new Date();
var minutes = now.getMinutes();
var snooze = minutes + 15;

A start?? Snooze returns only the minutes, of course. I need it to return the full date and time.

I've been searching for two days, how come I can't find anything referring to this at all?! X_x

Roku
07-09-2008, 10:46 PM
OK WHUT. Magically figured it out...:o

var snooze = now.setMinutes(now.getMinutes()+15));

I swear I was just fooling around with it!

I guess I'll leave this here in case it spares someone a few lost hours??

ljonny18
03-31-2009, 04:01 PM
Hey Roku - Thanks for leaving your post, it helped me out :)

Jon.