does anybody know how to show 2 days ahead of the current date? so today is 2nd january, 2007 .:. the script would present "4th january, 2007" I'd appreciate it alot. Thanks!
Here's a working example: <html> <body> <script type="text/javascript"> var d = new Date(); document.write (d.toLocaleString()) document.write ("<br/>"); var n = 2; // Number of days d.setTime( d.getTime() + 1000 * n * 86400 ); document.write (d.toLocaleString()) </script> </body> </html> Code (markup): Some reputation would be nice
It's not advisable to use time functions to calculate dates. var now=new Date(); alert(new Date(now.setDate(now.getDate()+2))) // Then format the properties of [I]now[/I] as required. Code (markup): Having said that, it's also inadvisable doing anything critical based on the client's system clock, which could be wrong.
Why ? I've made many programs written in Unix/C using time() function (on server side of course), and has been working for years (even work before and after the 2000 effect).
ajsa52: your code gave me both todays date and 2 days ahead, how do you make it to only show 2 days ahead?
Here it is, using only Date() functions to avoid fear of "Logic Ali" : <html> <body> <script type="text/javascript"> d1 = new Date(); var n = 2; // Number of days var d2 = new Date(d1.setDate(d1.getDate()+n)); document.write (d2.toLocaleString()) </script> </body> </html> Code (markup):
Replacing "toLocaleString" with "toLocaleDateString". You can find more info about Date functions Here