Re: Type Conversion with Date formatted as YYYYMMDD

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Mar 14, 3:58 pm, "Branco Medeiros" <branco.medei...@xxxxxxxxx>
wrote:
Mike wrote:
I have a string variable containing a date formatted as YYYYMMDD
For example - Dim x as string = "20070314"

If I try to perform a type conversion as follows I get an error:
Dim y as Date = CDATE(x)

<snip>

I guess you'll be glad to know that the Date class has a Shared method
to do just that:

Dim D As Date = Date.ParseExact(X, "yyyyMMdd", Nothing)

HTH.

Regards,

Branco.

It never ceases to amaze me the kinds of stuff that I overlook in the
Framework. I use the DateTime class all the time. I don't know how
many times I've manually coded that solution, and didn't need to. I
should have figured there'd be a Framework method for handling it. I
just didn't look in the right place for it.

Thanks for pointing that out, Bronco.


.



Relevant Pages

  • Re: Custom Attributes, Shared methods, Derived classes and reflection
    ... method on the base class is invoked through the derived class (since that's were my ... How would the assignment of the 'classtype' variable in the base's shared method be ... Dim x as string = MyDerivedClass.S_ValueFromMyAttribute ... It seems to me that GetType won't work here as it needs an explicit Type as its ...
    (microsoft.public.dotnet.languages.vb)
  • Re: String to Byte & Vice Versa
    ... shared method means you don't use an instance, you use a class name:) Although, in VB.Net you can use instance variables to call shared methods.. ... Dim instance As System.Text.Encoding ... Dim returnValue As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to write a service program that can call and run a script?
    ... > Dim p As New Process ... Always remember that 'Start' is a shared method of the 'Process' class. ... Herfried K. Wagner [MVP] ...
    (microsoft.public.dotnet.languages.vb)