?
Solved

Monday to Date

Posted on 2006-04-16
6
Medium Priority
?
496 Views
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.
0
Comment
Question by:broadbent
6 Comments
 
LVL 64

Expert Comment

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

Thanks;
Fernando
0
 
LVL 4

Author Comment

by:broadbent
ID: 16464570
The next Monday in this Month,Year .
The Time,Hour,Second is 14:00:00
0
 
LVL 64

Expert Comment

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

Fernando
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:broadbent
ID: 16464832
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.
a="Monday"
....
dim v,enddate as date
v = date.today
for i = 0 to 6
if v.dayofweek = a then enddate=v: exit for
v.adddays(1)
next i

0
 
LVL 3

Assisted Solution

by:maidinhtai
maidinhtai earned 375 total points
ID: 16464864
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
        MessageBox.Show(dt)
        Me.Close()
    End Sub
End Class
0
 
LVL 2

Accepted Solution

by:
manojkumarps earned 375 total points
ID: 16468020
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.

Regards,
Manoj
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

864 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