What day is today? Monday? Sunday?

BlitzMax Forums/BlitzMax Programming/What day is today? Monday? Sunday?

anyone know a better way to get it?


'day one for each month (year 1980)  2,5,6,2,4,7,2,5,1,3,6,1
Local base_day:Int[] =[0  ,0,4,5,1,3,6,1,4,0,2,5,0]
Local a:Float
Local months:String ="Jan01 Feb02 Mar03 Apr04 May05 Jun06 Jul07 Aug08 Sep09 Oct10 Nov11 Dec12"

year =Int(Right$(CurrentDate$(),4))
month =Int(Mid$(months,Instr(months,Mid$(CurrentDate$(),4,3))+3,2))
day =Int(Left$(CurrentDate$(),2))


a=(year-1980)/4#
b=(a-(Int a))*4

'+1+1+1+2 normal
'+2+1+1+1 for january, february     
If month>2 Then
	If b=4 Then b=5
Else
	If b>0 Then b:+1
EndIf

b:+day
c=((base_day[month]+(Int a)*5)+b) - (Int(((base_day[month]+(Int a)*5)+b)/7)*7)

Print
Print "Year: "+year+" Month: "+month+" Day: "+day
Print
Print "SUN MON TUE WED THU FRI SAT"
Print Left$("                            ",c*4)+"<*>" 'do you know a better way to tab? like tab(c*4) or spc(c*4)
Print
Print "or..."
Print
If c=0 Then c=6 Else c:-1
Print "MON TUE WED THU FRI SAT SUN"
Print Left$("                            ",c*4)+"<*>"
Print




'-----------------------------------------------------------------
'how many days have the month?
Local maxdays:Int[]=[0   ,31,28,31,30,31,30,31,31,30,31,30,31]
If (year Mod 4)=0 Then maxdays[2]=29

'now you can build a calendar
Print
Print " ---------------------------"
Print " MON TUE WED THU FRI SAT SUN"

'show me the first day
b:-day; c=((base_day[month]+(Int a)*5)+b) - (Int(((base_day[month]+(Int a)*5)+b)/7)*7)

d=0 'day counter
For weeks=0 To 5; line$=""
For days=1 To 7
If weeks*7+days > c And d < maxdays[month] Then
	d:+1; If d=day Then line$:+Right$(" <"+d+">",4) Else line$:+Right$("  "+d+" ",4)
Else
	line$:+"    "
EndIf
Next; Print line$
Next



Have you tried googling up 'Julian Day Calculator' ?
Here's a link with some Java source:

http://www.numerical-recipes.com/julian.html

For tabbing (via Print) try using ~t inside the ""

Not that this helps but I have a 'days between 2 dates caculator' which I might as well share with you:
' Juilan day calculator
' How many days between two dates?

Strict


Type jdcType
	Global month:TList
	Method New()
		month=New TList
		month.AddLast "JAN" ; month.AddLast "FEB" ; month.AddLast "MAR"
		month.AddLast "APR" ; month.AddLast "MAY" ; month.AddLast "JUN"
		month.AddLast "JUL" ; month.AddLast "AUG" ; month.AddLast "SEP"
		month.AddLast "OCT" ; month.AddLast "NOV" ; month.AddLast "DEC"
	End Method
	Function FindMonth(fm$)
		Local mcount%
		For Local m$=EachIn month
			mcount:+1
			If fm.ToUpper() = m$ Return mcount
		Next
	End Function
	Function JulianDays(txt$)
  		Local d=Int(Left(txt$,2))
 		Local m=Int(FindMonth(Mid(txt$,4,3)))
  		Local y=Int(Right(txt$,4))
  		Local jd=(1461*(y+4800+(m-14)/12))/4+(367*(m-2-12*((m-14)/12)))/12-(3*((y+4900+(m-14)/12)/100))/4+d-32075
  		Return jd
	End Function
End Type

Local jdc:jdcType=New jdcType


Local todate$="25 DEC 2005"


Print "~n Days between TODAY and "+todate$+" = "+(jdc.JulianDays(todate$) - jdc.JulianDays(CurrentDate()))
End


Thanks, I'll check the page and find the way to get the day.

http://www.blitzbase.de/quellcode/datumarithmetik.bb

codes for bb2d/3d/plus