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

Q626 How can I add two times together, 08:30 and 08:45 and get 17:15?

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

Q626 How can I add two times together, 08:30 and 08:45 and get 17:15?

Try:

<SCRIPT LANGUAGE="JavaScript"><!--
var t1 = '08:30', t2 = '08:45';
var m = (t1.substring(0,t1.indexOf(':'))-0) * 60 +
        (t1.substring(t1.indexOf(':')+1,t1.length)-0) +
        (t2.substring(0,t2.indexOf(':'))-0) * 60 +
        (t2.substring(t2.indexOf(':')+1,t2.length)-0);
var h = Math.floor(m / 60);
document.write(h + ':' + (m - (h * 60)));
//--></SCRIPT>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


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