Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for yesterday.kix

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

  1. ; Yesterday.kix,  Version 1.00
  2. ; Display today's and yesterday's date in two formats
  3. ; Written by Rob van der Woude
  4. ; http://www.robvanderwoude.com
  5.  
  6. ; Today's date in YYYYMMDD format
  7. $SortDate = ( 10000 * @YEAR ) + ( 100 * @MONTHNO ) + @MDAYNO
  8.  
  9. ; Calculate yesterday's date
  10. $YesterD = @MDAYNO - 1
  11. $YesterM = @MONTHNO
  12. $YesterY = @YEAR
  13.  
  14. ; It gets tricky when today is the first day of the month
  15. IF $YesterD = 0
  16. 	GOSUB RollMonth
  17. ENDIF
  18.  
  19. ; Yesterday's date in YYYYMMDD format
  20. $SortYest = ( 10000 * $YesterY ) + ( 100 * $YesterM ) + $YesterD
  21.  
  22. ; Display the results
  23. ? "Format:     YYYYMMDD  (DD/MM/YYYY)"
  24. ? "=================================="
  25. ? "Today:      $SortDate  (@MDAYNO/@MONTHNO/@YEAR)"
  26. ? "Yesterday:  $SortYest  ($YesterD/$YesterM/$YesterY)"
  27. ?
  28.  
  29. ; Done
  30. EXIT
  31.  
  32.  
  33. ; * * * * * * * *  Subroutines  * * * * * * * *
  34.  
  35.  
  36. ; Subroutine to get yesterday's date if today is the first day of the month
  37. :RollMonth
  38. $YesterM = $YesterM - 1
  39. SELECT
  40. 	CASE $YesterM = 0 ; Today is January 1st
  41. 		$YesterD = 31
  42. 		$YesterM = 12
  43. 		$YesterY = @YEAR - 1
  44. 	CASE $YesterM = 1 ; Today is February 1st
  45. 		$YesterD = 30
  46. 	CASE $YesterM = 2 ; Today is March 1st
  47. 		$YesterD = 28
  48. 		GOSUB LeapYear
  49. 	CASE $YesterM = 3 ; Today is April 1st
  50. 		$YesterD = 31
  51. 	CASE $YesterM = 4 ; Today is May 1st
  52. 		$YesterD = 30
  53. 	CASE $YesterM = 5 ; Today is June 1st
  54. 		$YesterD = 31
  55. 	CASE $YesterM = 6 ; Today is July 1st
  56. 		SET YesterD=30
  57. 	CASE $YesterM = 7 ; Today is August 1st
  58. 		$YesterD = 31
  59. 	CASE $YesterM = 8 ; Today is September 1st
  60. 		$YesterD = 31
  61. 	CASE $YesterM = 9 ; Today is October 1st
  62. 		$YesterD = 30
  63. 	CASE $YesterM = 10 ; Today is November 1st
  64. 		$YesterD = 31
  65. 	CASE $YesterM = 11 ; Today is December 1st
  66. 		$YesterD = 30
  67. ENDSELECT
  68. RETURN
  69.  
  70.  
  71. ; Subroutine to calculate if this year is a leap year
  72. ; (I am not sure if the century calculations are right)
  73. :LeapYear
  74. ; If the year divisable by 4 then it is a leap year . . .
  75. $LeapYear = ( @YEAR / 4 ) * 4
  76. IF $LeapYear = @YEAR
  77. 	$YesterD = 29
  78. ENDIF
  79. ; . . . unless it is also divisible by 100 . . .
  80. $LeapYear = ( @YEAR / 100 ) * 100
  81. IF $LeapYear = @YEAR
  82. 	$YesterD = 28
  83. ENDIF
  84. ; . . . but when it is divisible by 400 it is a leap year again (?)
  85. $LeapYear = ( @YEAR / 400 ) * 400
  86. IF $LeapYear = @YEAR
  87. 	$YesterD = 29
  88. ENDIF
  89. RETURN
  90.  

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