Day of the week

vb6 Finland
  • 13 years ago

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

    Thankyou

  • 13 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://www.merlyn.demon.co.uk/datelinx.htm

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

    From:

    http://www.developerfusion.co.uk/forums/thread/97438/

  • 13 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

  • 13 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
















  • 13 years ago

    With the risk of being considered a smartass... Wink [;)]

    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

Post a reply

Enter your message below

Sign in or Join us (it's free).

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.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov