none
what is the meaning of Convert.ToDateTime(null) and it's VB.NET equivalent RRS feed

  • Question

  • Hi
    everybody
    can anybody tell me what is the meaning of Convert.ToDateTime(null).

    I have this in C#.NET and i wan't it's VB.NET equivalent

    Please help
    Thanks
    Sunday, December 6, 2009 7:48 AM

Answers

  • Hi,

    Convert.ToDateTime is a convert function that converts any value to a datetime type.

    Convert.ToDateTime(null) will result a datetime that represents 01.01.0001(smallest value of datetime)

    and at vb you can write this like

    Convert.ToDateTime(Nothing)

    Also here is a documentation for Convert.ToDateTime function

    http://msdn.microsoft.com/en-us/library/system.convert.todatetime.aspx

    And in this example you are using Convert.ToDateTime(object) overload and here is a sample for this overload.
    http://msdn.microsoft.com/en-us/library/ky38w316.aspx
    • Marked as answer by nccsbim071 Sunday, December 6, 2009 8:07 AM
    Sunday, December 6, 2009 7:56 AM
  • Ok thanks for the link

    I solved it: i wrote my code like this:

     Dim obj As Object = Nothing
     _fileDateTime = Convert.ToDateTime(obj)

    and it worked fine

    Thanks a lot.
    • Marked as answer by nccsbim071 Sunday, December 6, 2009 8:07 AM
    Sunday, December 6, 2009 8:06 AM
  • You could also do this without creating a dummy variable:
    _fileDateTime = Convert.ToDateTime(CType(Nothing, Object))

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Marked as answer by nccsbim071 Monday, December 7, 2009 3:49 AM
    Sunday, December 6, 2009 3:42 PM

All replies

  • Hi,

    Convert.ToDateTime is a convert function that converts any value to a datetime type.

    Convert.ToDateTime(null) will result a datetime that represents 01.01.0001(smallest value of datetime)

    and at vb you can write this like

    Convert.ToDateTime(Nothing)

    Also here is a documentation for Convert.ToDateTime function

    http://msdn.microsoft.com/en-us/library/system.convert.todatetime.aspx

    And in this example you are using Convert.ToDateTime(object) overload and here is a sample for this overload.
    http://msdn.microsoft.com/en-us/library/ky38w316.aspx
    • Marked as answer by nccsbim071 Sunday, December 6, 2009 8:07 AM
    Sunday, December 6, 2009 7:56 AM
  • I already tried using your method but i get this error:

    Error    7    Overload resolution failed because no accessible 'ToDateTime' is most specific for these arguments:
        'Public Shared Function ToDateTime(value As Char) As Date': Not most specific.
        'Public Shared Function ToDateTime(value As Boolean) As Date': Not most specific.
        'Public Shared Function ToDateTime(value As Byte) As Date': Not most specific.
        'Public Shared Function ToDateTime(value As Date) As Date': Not most specific.    D:\\FTPClientVS2005_VB\FTPClientVS2005_VB\FTP\FTPClient.vb    772    37    FTPClientVS2005_VB

    My vb.net statement is like this:
     _fileDateTime = Convert.ToDateTime(Nothing)

    Sunday, December 6, 2009 8:02 AM
  • Ok thanks for the link

    I solved it: i wrote my code like this:

     Dim obj As Object = Nothing
     _fileDateTime = Convert.ToDateTime(obj)

    and it worked fine

    Thanks a lot.
    • Marked as answer by nccsbim071 Sunday, December 6, 2009 8:07 AM
    Sunday, December 6, 2009 8:06 AM
  • You could also do this without creating a dummy variable:
    _fileDateTime = Convert.ToDateTime(CType(Nothing, Object))

    Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
    • Marked as answer by nccsbim071 Monday, December 7, 2009 3:49 AM
    Sunday, December 6, 2009 3:42 PM
  • Thanks david, i works as well
    Thanks a lot
    Monday, December 7, 2009 3:49 AM