broadbent
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.
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.
ASKER
The next Monday in this Month,Year .
The Time,Hour,Second is 14:00:00
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
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
ASKER
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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