Parsing a Date.Now using

cmdolcet used Ask the Experts™
I am trying to parse a return value of the

I have the following:

'On a button control I have the following

Dim date1 as Date =

'I would like to parse the returned value # 9/5/2019 01:27:04 PM#

Open in new window

The format I am trying to get is the following

So the returned value above would look like:


Any help would be amazing.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jorge SanchezSoftware Engineer

This should work:

Date.Now.ToString("<mm,HH,dd,") & cint(Date.Now.DayOfWeek) & Date.Now.ToString(",MM,yyyy>")

Open in new window

Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

In .Net we have DateTime data type and everything that you need is available as a property. So, date1.Hour will get you Hours value and so on. All you need to do is use concatenation to get desired results.

date1.Hour &  "," & date1.Minute...
Senior .Net Consultant
Top Expert 2016
The missing part in the ToString is DayOfWeek. So you need to do a bit of gymnastic:
            dim d as DateTime = DateTime.Now
            Dim s as String = d.ToString("mm,hh,dd,@w@,M,yyyy").Replace("@w@", Convert.ToInt32(d.DayOfWeek).ToString)

Open in new window

More details at

As Eric states:
Imports System

Module Program
	Sub Main(args As String())
		Dim [date] As DateTime = DateTime.Now
		Console.WriteLine($"<{[date].ToString("mm,hh,dd,@w@,MM,yyyy")}>".Replace("@w@", Convert.ToInt32([date].DayOfWeek)))
	End Sub
End Module

Open in new window

Produces the following output -Capture.PNG-saige-
Here is a function that you could use:
 Function Adjustdate(ByVal i As DateTime) As String
        ' <min,hour,day,weekday,month,year>
        Return "<" & i.Minute & "," & i.Hour & "," & i.Day & "," & i.DayOfWeek & "," & i.Month & "," & i.Year & ">"
    End Function

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial