Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q147 How do you subtract X hours from a date?

irt.org | Knowledge Base | JavaScript | Date | Q147 [ previous next ]

Q147 How do you subtract X hours from a date?

The following subtracts five hours from the current date and time:

<SCRIPT LANGUAGE = 'JavaScript'><!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

var date = new Date();
var date = new Date(Date.UTC(y2k(date.getYear()),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()) - 5*60*60*1000);
document.write(date);
//--></SCRIPT>

Feedback on 'Q147 How do you subtract X hours from a date?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.