Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for yesterday.vbs

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

  1. ' Yesterday.vbs,  Version 1.01 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. strHead    = "Format:     YYYYMMDD  (DD/MM/YYYY)" & Chr(13) & Chr(10) & _
  9.              "==================================" & Chr(13) & Chr(10)
  10.  
  11.  
  12. ' Get current year
  13. strYear = DatePart("yyyy",Date)
  14.  
  15. ' Get current month, add leading zero if necessary
  16. If DatePart("m",Date) < 10 Then
  17. 	strMonth = 0 & DatePart("m",Date)
  18. Else
  19. 	strMonth = DatePart("m",Date)
  20. End If
  21.  
  22. ' Get current day, add leading zero if necessary
  23. If DatePart("d",Date) < 10 Then
  24. 	strDay = 0 & DatePart("d",Date)
  25. Else
  26. 	strDay = DatePart("d",Date)
  27. End If
  28.  
  29. ' Format output for today
  30. strToday = "Today:      " & strYear & strMonth & strDay & "  (" & _
  31.            strDay & "/" & strMonth & "/" & strYear & ")" & Chr(13) & Chr(10)
  32.  
  33. ' Calculate yesterday's date
  34. dtmYesterday = DateAdd("d",-1,Date)
  35.  
  36. ' Get yesterday's year
  37. strYear      = DatePart("yyyy",dtmYesterday)
  38.  
  39. ' Get yesterday's month, add leading zero if necessary
  40. If DatePart("m",dtmYesterday) < 10 Then
  41. 	strMonth = 0 & DatePart("m",dtmYesterday)
  42. Else
  43. 	strMonth = DatePart("m",dtmYesterday)
  44. End If
  45.  
  46. ' Get yesterday's day, add leading zero if necessary
  47. If DatePart("d",dtmYesterday) < 10 Then
  48. 	strDay = 0 & DatePart("d",dtmYesterday)
  49. Else
  50. 	strDay = DatePart("d",dtmYesterday)
  51. End If
  52.  
  53. ' Format output for yesterday
  54. strYest = "Yesterday:  " & strYear & strMonth & strDay & "  (" & _
  55.           strDay & "/" & strMonth & "/" & strYear & ")"
  56.  
  57. ' Display the result
  58. Wscript.Echo( strHead & strToday & strYest )
  59.  

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