Changing date format with Regex

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

I have a function that returns the date in the following format:

6/22/2005

I need the format to be:

050622

I have zero experience with RegEx but I believe that would be the way to go
here. Can someone give me some info on this? Or if RegEx isn't the way,
what would be the best method to re-format the date?
 
Terry Olsen said:
It is a string. It could be a datetime if I took the .ToString off
the end.

If it's always this format:

Shared Function GetDate(ByVal s As String) As Date

Dim Parts As String()

Parts = s.Split("/"c)

Return New Date( _
Integer.Parse(Parts(2)), _
Integer.Parse(Parts(0)), _
Integer.Parse(Parts(1)) _
)

End Function

You might add some checks.

After converting to Date, uses the Date's ToString method to convert to any
format you want.

Armin
 
Terry Olsen said:
It is a string. It could be a datetime if I took the .ToString off
the end.

If it's always this format:

Shared Function GetDate(ByVal s As String) As Date

Dim Parts As String()

Parts = s.Split("/"c)

Return New Date( _
Integer.Parse(Parts(2)), _
Integer.Parse(Parts(0)), _
Integer.Parse(Parts(1)) _
)

End Function

You might add some checks.

After converting to Date, uses the Date's ToString method to convert to any
format you want.

Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top