# Day of the week

vb6
• 14 years ago

Does anyone know how to calculate the week day from a date. The date is in dd/mm/yyyy format.

Thankyou

• 14 years ago

I am afraid that I do not have any VB6 code handy, however the following C# should point you in the right direction:

`// Tomohiko Sakamoto's algorithm (alternative to Zeller's Congruence) string[] DayNames = new string[] { "Sun","Mon","Tue","Wed","Thu","Fri","Sat" }; int[] t = new int[] { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; if (mm < 3) yy = yy - 1; int dow = (yy + yy/4 - yy/100 + yy/400 + t[mm-1] + dd) % 7; return DayNames[dow];`

Where, dd, mm and yy represent the date, e.g. 01, 02, 2006

More here:

http://www.cs.uwaterloo.ca/~alopez-o/math-faq/mathtext/node39.html

http://en.wikipedia.org/wiki/Zeller's_congruence

From:

• 14 years ago

I'd say that you could use the standard Weekday() function.  According to the object-browser it takes a date as the parameter and returns the day of the week.

Ciao,

Erwin

• 14 years ago

Just to elaborate on what Erwin suggested, the WeekDay function accepts just one parameter, a valid date, and returns a code representing the current day.  By using a Select Case statement you can test the code that is generated:

Select Case Weekday(Now)
Case vbSunday
Label5.Caption = "sunday"
Case vbMonday
Label5.Caption = "monday"
Case vbTuesday
Label5.Caption = "tuesday"
Case vbWednesday
Label5.Caption = "wednesday"
Case vbThursday
Label5.Caption = "thursday"
Case vbFriday
Label5.Caption = "friday"
Case vbSaturday
Label5.Caption = "saturday"
End Select

• 14 years ago

With the risk of being considered a smartass...

The weekday function actually accepts 2 parameters: the date you want to evaluate, and optionally the day that you consider the first day of the week.

For today (Friday April 6)  Weekday(Now, vbMonday) will return 5, whereas Weekday(Now, vbSunday) will return 6.

Hope this will help you to solve the problem you were facing.

Erwin

### Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

### Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match”