PDA

View Full Version : Day of week



blaidd drwg
06-17-2014, 01:14 PM
Is there a better way to get day of the week then:

Public Function DayOfWeek(ChartID, Record)
Dim DAYS(7)
DAYS(0) = "Sunday"
DAYS(1) = "Monday"
DAYS(2) = "Tuesday"
DAYS(3) = "Wednesday"
DAYS(4) = "Thursday"
DAYS(5) = "Friday"
DAYS(6) = "Saturday"

Dim MT(12)
MT(0) = 0
MT(1) = 31
MT(2) = 59
MT(3) = 90
MT(4) = 120
MT(5) = 151
MT(6) = 181
MT(7) = 212
MT(8) = 243
MT(9) = 273
MT(10) = 304
MT(11) = 334

Dim y
Dim m
Dim d
Dim r

y = CINT(GetYear(CLNG(ChartID), CLNG(Record)))
m = CINT(GetMonth(CLNG(ChartID), CLNG(Record)))
d = CINT(GetDay(CLNG(ChartID), CLNG(Record)))
r = 0
if ((y mod 4 = 0) and (y mod 100 <> 0) and (m > 2)) Then
r = 1
End If

DayOfWeek = CSTR(DAYS(CINT(((y-1)*365 + ((y-1) \ 4) - ((y-1) \ 100) + MT(m-1) + r + d + 5) mod 7)))
End Function

Hassan-HS
06-17-2014, 06:05 PM
Hello,


you can use this Vb-script built-in function



MsgBox WeekdayName(Weekday(GetTime(0,bars(0))))

blaidd drwg
06-17-2014, 10:03 PM
gr8 :-)
thank You.