Results 1 to 4 of 4

Thread: SOLVED: Check if a Date is on the Weekend & Skip

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    58

    SOLVED: Check if a Date is on the Weekend & Skip

    Hello, I have a script that needs to only carry out and action if the day is not a weekend. Could somebody assist with this code?


    Code:
    1. Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         'convert date1 to a string
    4.         Dim StartDate As Date = DateTimePicker1.Value
    5.         Dim StartDateStr As String
    6.  
    7.         'get date2
    8.         Dim EndDate As Date = DateTimePicker2.Value
    9.  
    10.         'get the number of days between date1 and date2
    11.         Dim intDays As Integer = EndDate.Subtract(StartDate).Days()
    12.         Dim i As Integer
    13.  
    14.             For i = 0 To intDays
    15.  
    16.                       'Check If StartDate is a not a weekend
    17.                      
    18.                       'if it is not a weekend
    19.                             'Do code
    20.  
    21.                       Else
    22.                      
    23.                       EndIf
    24.  
    25.                 StartDate = StartDate.Date.AddDays(1D)
    26.             Next
    27.  
    28.     End Sub
    Last edited by Eksbee; Feb 18th, 2010 at 11:59 AM.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Check if a Date is on the Weekend & Skip

    Code:
            Dim dt As DateTime = DateTime.Now
            If Not (dt.DayOfWeek = DayOfWeek.Saturday OrElse dt.DayOfWeek = DayOfWeek.Sunday) Then
                'not sat or sun
            End If
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Check if a Date is on the Weekend & Skip

    You can look at DayOfWeek() that will give you a number from 0 to 6
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    58

    Re: Check if a Date is on the Weekend & Skip

    Thank you, geniuses!

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