Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for yesterday.js

(view source code of yesterday.js as plain text)

  1. // Yesterday.js,  Version 1.00 for Windows Script Host 2.00
  2. // Display today's and yesterday's date in two formats
  3. //
  4. // Written by Rob van der Woude
  5. // http://www.robvanderwoude.com
  6.  
  7. // Specify header
  8. strHead1 = "Format:     YYYYMMDD  (DD/MM/YYYY)";
  9. strHead2 = "==================================";
  10.  
  11. // Create Date object
  12. objToday = new Date();
  13.  
  14. // Get today's year, month and day
  15. year  = objToday.getFullYear();
  16. month = objToday.getMonth() + 1;
  17. if ( month < 10 )
  18. 	{
  19. 	month = "0" + month;
  20. 	};
  21. day   = objToday.getDate();
  22. if ( day < 10 )
  23. 	{
  24. 	day = "0" + day;
  25. 	};
  26.  
  27. // Format output for today
  28. strToday = "Today:      " + year + month + day + "  (" + day;
  29. strToday = strToday + "/" + month + "/" + year + ")";
  30.  
  31. // Get current date in milliseconds since January 1, 1970
  32. today = objToday.valueOf();
  33.  
  34. // Subtract 1 day
  35. oneDay = 1000 * 24 * 60 * 60;
  36. yesterday = today - oneDay;
  37. objToday.setTime(yesterday);
  38.  
  39. // Get yesterday's year, month and day
  40. year  = objToday.getFullYear();
  41. month = objToday.getMonth() + 1;
  42. if ( month < 10 )
  43. 	{
  44. 	month = "0" + month;
  45. 	};
  46. day   = objToday.getDate();
  47. if ( day < 10 )
  48. 	{
  49. 	day = "0" + day;
  50. 	};
  51.  
  52. // Format output for yesterday
  53. strYest = "Yesterday:  " + year + month + day + "  (" + day;
  54. strYest = strYest + "/" + month + "/" + year + ")";
  55.  
  56. // Display the result
  57. WScript.Echo( strHead1 );
  58. WScript.Echo( strHead2 );
  59. WScript.Echo( strToday );
  60. WScript.Echo( strYest );
  61.  

page last modified: 2024-04-16; loaded in 0.0053 seconds