?
Solved

How to find the date for Monday in vb.net

Posted on 2003-02-22
2
Medium Priority
?
1,882 Views
Last Modified: 2012-06-27
In VB6 I could use the following code to find the date for Monday of the current week:
dteMonday = Format(Date - (IIf(Weekday(Date) >= vbMonday, Weekday(Date) - vbMonday, 7 - (vbMonday - Weekday(Date)))))

Is there a way to do this in vb.net? Thanks!
0
Comment
Question by:myester
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 800 total points
ID: 7999087
I think that must give you previous Monday

        Dim dtMon As Date
        If Today.DayOfWeek = DayOfWeek.Monday Then
            dtMon = Today
        Else
            dtMon = Today.AddDays(1 - Today.DayOfWeek)
        End If
0
 

Author Comment

by:myester
ID: 7999959
iboutchkine, thanks for the help. This is much easier to do in vb.net than in VB6. I had to make one small addition to account for if Today is Sunday. If Today is Sunday then dtMon was returing the next day vs the previous Monday. I.E. if Today is Sunday Feb 23rd dtMon was returing 02/24/2003 vs 02/17/2003 which is what I am looking for. I corrected for it like this:

Select Case Today.DayOfWeek
            Case DayOfWeek.Monday
                dtMon = Today
            Case DayOfWeek.Sunday
                dtMon = Today.AddDays(Today.DayOfWeek - 6)
            Case Else
                dtMon = Today.AddDays(1 - Today.DayOfWeek)
End Select

Thanks again for you help.
0

Featured Post

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question