Microsoft Developer Network > Página principal de foros > Visual Basic General > System.Convert.ToDateTime(string) As Date
Formular una preguntaFormular una pregunta
 

RespondidaSystem.Convert.ToDateTime(string) As Date

  • domingo, 09 de septiembre de 2007 14:17vin25 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    Hi All

     

    I have written a code in visual basic 2005 to compare between dates

    If CDate(tocomparewith_1) >= d1 And CDate(tocomparewith_2) <= d2 Then

     

    tocomparewith_1 & tocomparewith_2 are String formats.

    d1 and d2 are Date formats.

     

    The string and date are in the following format "MM/dd/yyyy H:mm"

     

    now no matter if i use Cdate(tocomparewith_1) or System.Convert.ToDateTime(tocomparewith_1)

    It returns an error if tocomparewith_1 value is "12/23/2007 6:23"

    i guess Cdate or System.Convert.ToDateTime needs the date in format "dd/MM/yyyy H:mm"

    caues it works fine in that way.

    Now the problem is how do i present Cdate or System.Convert.ToDateTime with a string in that format.

     

    Also i havent heard of any function that allows me to specify the existing format of date along with the convert to date format. cause if i use the format( ) function to covert to "dd/MM/yyyy H:mm" it doest give me consistent results.

    eg

    Existing Format / Date  "MM/dd/yyyy" / "06/09/2007"

    On one system it reads it as 06 sep 2007 on other system it reads the same date as june 09 2007

     

    Thanks in advance for your time.

     

     

     

Respuestas

Todas las respuestas