Link to home
Start Free TrialLog in
Avatar of cmdolcet
cmdolcetFlag for United States of America

asked on

Parsing a Date.Now using vb.net

I am trying to parse a return value of the date.now

I have the following:

'On a button control I have the following

Dim date1 as Date = Date.now

'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
<min,hour,date,weekday,month,year>

So the returned value above would look like:

<27,01,05,4,9,2019>

Any help would be amazing.
Avatar of Jorge Sanchez
Jorge Sanchez
Flag of Ecuador image

This should work:

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

Open in new window

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...

https://docs.microsoft.com/en-us/dotnet/api/system.datetime?view=netframework-4.8#properties
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

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