-
July 13th, 2017, 03:15 PM
#1
Assign DayOfWeek as variable
Here is my code which calculate number of days between two dates except weekends. which worked fine but need help to assign DayOfWeek as variable like:
Code:
daya = "Friday"
dayb = "Saturday"
DayOfWeek of the week change some time Sunday, etc..
Dim sdate As Date = DateTime.Parse(txtfdate.Text).ToString("MM/dd/yyyy")
Dim edate As Date = DateTime.Parse(txttdate.Text).ToString("MM/dd/yyyy")
Dim RqHours = 0
Dim totalDays = (edate - sdate).Days
Dim daya As string = "Friday"
Dim dayb As string= "Saturday"
For i = 0 To totalDays
Dim weekday As DayOfWeek = sdate.AddDays(i).DayOfWeek
If weekday <> DayOfWeek.Friday AndAlso weekday <> DayOfWeek.Saturday Then
'If weekday <> daya AndAlso weekday <> dayb Then
RqHours += 1
End If
Next
Last edited by 2kaud; July 13th, 2017 at 03:47 PM.
Reason: Added code tags
-
July 13th, 2017, 05:03 PM
#2
Re: Assign DayOfWeek as variable
-
July 14th, 2017, 07:03 AM
#3
Re: Assign DayOfWeek as variable
Originally Posted by Arjay
What is the problem?
The following code working well:
Code:
For i = 0 To totalDays
Dim weekday As DayOfWeek = sdate.AddDays(i).DayOfWeek
If weekday <> DayOfWeek.Friday AndAlso weekday <> DayOfWeek.Saturday Then
RqHours += 1
End If
Next
here is got error:
Code:
Dim daya As string = "Friday"
Dim dayb As string= "Saturday"
For i = 0 To totalDays
Dim weekday As DayOfWeek = sdate.AddDays(i).DayOfWeek
If weekday <> daya AndAlso weekday <> dayb Then
RqHours += 1
End If
Next
Last edited by 2kaud; July 14th, 2017 at 09:41 AM.
Reason: Added code tags
-
July 14th, 2017, 09:41 AM
#4
Re: Assign DayOfWeek as variable
[When posting code, please use code tags. Go Advanced, select the formatted code and click '#'].
Cheers!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 14th, 2017, 03:14 PM
#5
Re: Assign DayOfWeek as variable
Originally Posted by kmafsar
The following code working well:
Code:
For i = 0 To totalDays
Dim weekday As DayOfWeek = sdate.AddDays(i).DayOfWeek
If weekday <> DayOfWeek.Friday AndAlso weekday <> DayOfWeek.Saturday Then
RqHours += 1
End If
Next
here is got error:
Code:
Dim daya As string = "Friday"
Dim dayb As string= "Saturday"
For i = 0 To totalDays
Dim weekday As DayOfWeek = sdate.AddDays(i).DayOfWeek
If weekday <> daya AndAlso weekday <> dayb Then
RqHours += 1
End If
Next
What is the error? Does the code not compile or is it a runtime error? If the code doesn't compile, then you have a mismatched type between the strings defined as "Friday" and "Saturday" and the DayOfWeek enum values (enums are defined as integers).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|