Results 1 to 4 of 4

Thread: Need help for getting the number of days excluding sunday in a month

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2014
    Posts
    95

    Need help for getting the number of days excluding sunday in a month

    Our system is almost done and I check all the requirements in our system base on the manual system...

    and I missed one feature on a report that will get the Average of students who logged-in in a month

    here's the formula

    Average = Total / Number of days in a month

    Average = 2000 / 28(February)

    but the 28 days is include weekends....

    how will I get 24 days? since the school still open on saturday

    here's my code on how I get the number of days in a month

    Code:
    Label12.Text = DateTime.DaysInMonth(Date.Now.Year, Date.Now.Month)
    credit MSDN
    Last edited by MeSH; Feb 19th, 2015 at 08:06 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,403

    Re: Need help for getting the number of days excluding sunday in a month

    try this:

    Code:
    Dim days As Integer = Date.DaysInMonth(Now.Year, Now.Month)
    Dim sundays As Integer = Enumerable.Range(1, days).Count(Function(x) Weekday(New Date(Now.Year, Now.Month, x)) = 1)
    MsgBox(days - sundays)

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,963

    Re: Need help for getting the number of days excluding sunday in a month

    couldn't you just do it like this:

    Code:
    Dim days As Integer = Enumerable.Range(1, days).Count(Function(x) Weekday(New Date(Now.Year, Now.Month, x)) <> 1)
    MsgBox(days.tostring)
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,403

    Re: Need help for getting the number of days excluding sunday in a month

    nope...

    Code:
    Dim days As Integer = Enumerable.Range(1, days).Count(Function(x) Weekday(New Date(Now.Year, Now.Month, x)) <> 1)
    MsgBox(days.tostring)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width