Monday to Date

Posted on 2006-04-16
Last Modified: 2010-04-23
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.
Question by:broadbent
    LVL 62

    Expert Comment

    by:Fernando Soto
    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.

    LVL 4

    Author Comment

    The next Monday in this Month,Year .
    The Time,Hour,Second is 14:00:00
    LVL 62

    Expert Comment

    by:Fernando Soto
    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.

    LVL 4

    Author Comment

    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 =
    for i = 0 to 6
    if v.dayofweek = a then enddate=v: exit for
    next i

    LVL 3

    Assisted Solution

    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
    LVL 2

    Accepted Solution

    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.


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now