Link to home
Start Free TrialLog in
Avatar of broadbent
broadbentFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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.
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

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
Avatar of broadbent

ASKER

The next Monday in this Month,Year .
The Time,Hour,Second is 14:00:00
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
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

SOLUTION
Avatar of maidinhtai
maidinhtai

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial