Ooops
November 25, 2020, 07:33:13 AM

Author Topic: [bmx] Day of Year by xlsior [ 1+ years ago ]  (Read 763 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Day of Year by xlsior [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Day of Year
Author : xlsior
Posted : 1+ years ago

Description : The code below will return the day of the year for any date, taking leap years into consideration as well.

e.g. January 1st will be 1, December 31st will be either 365 or 366, depending on leap years.

<a href="http://www.xlsior.org/" target="_blank">http://www.xlsior.org[/url]


Code :
Code: BlitzMax
  1. ' Day of the Year
  2. '
  3. ' By Marc van den Dikkenberg
  4. '
  5. Strict
  6. Print "Day of the year: "+DayNumber("05 Aug 2007")      ' Specific Date
  7. Print "Day of the year: "+DayNumber("")                                 ' Returns Current Date
  8.  
  9.  
  10. Function DayNumber(SomeDate:String)             ' Date in form: "DD MMM YYYY", e.g.  "02 APR 2007"
  11.         If SomeDate="" Then    
  12.                 SomeDate = CurrentDate$()               ' If no date specified, use today's date
  13.         End If
  14.  
  15.         Local Dag:Int[]=[31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31]
  16.         Local Maand:String[]=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"]
  17.         Local YearStartPoint:Int=0
  18.         Local Jaar:Int=Int(Right$(SomeDate,4))
  19.         Local MonthCount:Int=0
  20.         Local TotalDays:Int=0
  21.         Local TempVar:Int=0
  22.  
  23.         If ((Jaar Mod 4) = 0 And (Jaar Mod 100) <> 0) Or ((Jaar Mod 4) = 0 And (Jaar Mod 400) = 0) Then
  24.                 ' It's a Leap Year
  25.                 YearStartPoint=12
  26.         Else
  27.                 ' It's not a Leap Year
  28.                 YearStartPoint=0
  29.         End If
  30.  
  31.         For TempVar:Int=0 To 11
  32.                 If Upper(Mid$(SomeDate,4,3))=maand[TempVar] Then
  33.                         MonthCount:Int=TempVar:Int
  34.                         Exit
  35.                 End If
  36.         Next
  37.         For Tempvar:Int=0 To MonthCount:Int-1
  38.                 TotalDays:Int=TotalDays:Int+dag[TempVar+YearStartPoint]
  39.         Next
  40.         TotalDays:Int=TotalDays:Int+Int(Left$(SomeDate,2))
  41.         Return TotalDays
  42. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal