• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 501
  • Last Modified:

Monday to Date

I've looked everywhere, so finally here is the question.

I have a string - Monday,14:00:00

And I want to convert it into a date so that Monday becomes the next monday in the month.

I have a long winded method, I am too ashamed to show, but I'm sure someone has a very neat and clever answer.
2 Solutions
Fernando SotoRetiredCommented:
Hi broadbent,

In your statement you say, "I have a string - Monday,14:00:00". But which Monday? Your statement is missing date and year. Can you make this clear.

broadbentAuthor Commented:
The next Monday in this Month,Year .
The Time,Hour,Second is 14:00:00
Fernando SotoRetiredCommented:
Hi broadbent;

This code will give you what you want if the string is a valid day and date and in that format.

        Dim startDate As String = "Monday April 17, 2006 14:00:00"
        Dim endDate As String
        Dim dt As DateTime
        dt = DateTime.Parse(startDate)
        dt = dt.AddDays(7)
        endDate = dt.ToString("ddd MMMM dd, yyyy HH:mm:ss")

I hope that this is of some help.

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

broadbentAuthor Commented:
Sorry but I need the next date from today when is Monday (say)
Your code doesn't do that.

This is what I have written.
dim v,enddate as date
v = date.today
for i = 0 to 6
if v.dayofweek = a then enddate=v: exit for
next i

I have written these code and hope it works:
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As DateTime = Today
        If Today.DayOfWeek <> DayOfWeek.Sunday Then dt = dt.AddDays(-Today.DayOfWeek) Else dt = dt.AddDays(-7)
        dt = dt.AddDays(1) 'dt here is monday of this week
        dt = dt.AddDays(7) 'dt here is the next monday of next week
    End Sub
End Class
Hello broadbent,
            As you are having the date of yours in a string. Convert it into long date format. The date has an option to add days to it. Add the days ie 7 in your case and display it in the long date format asd the complete time with seconds will be maintained.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now