Results 1 to 5 of 5

Thread: Datetime problem

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Datetime problem

    In windows 7 am facing the below problem, when converting datetime.


    Code:
    ?Convert.ToDateTime("7/15/2010 9:18:40 AM").ToString("dd-MMM-yyyy")
    Run-time exception thrown : System.FormatException - String was not recognized as a valid DateTime.

    is there any error in converting.
    Visual Studio.net 2010
    If this post is useful, rate it


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Datetime problem

    Your string is presumably in a format that is not recognised by your current culture. If you want to use a specific format then use a specific format, i.e. call Date.ParseExact and specify the format the string is in.

  3. #3
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Re: Datetime problem

    where you getting that datetime from vb.net... Is it from datetimepicker value? can you say correct problem of yours??

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: Datetime problem

    Quote Originally Posted by vijy View Post
    In windows 7 am facing the below problem, when converting datetime.


    Code:
    ?Convert.ToDateTime("7/15/2010 9:18:40 AM").ToString("dd-MMM-yyyy")
    Run-time exception thrown : System.FormatException - String was not recognized as a valid DateTime.

    is there any error in converting.
    Assuming that you typed that into the debugger, I agree with John. I copied / pasted it into my debugger and it worked fine.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Re: Datetime problem

    Try this..

    dim dat1 as date

    dat1 = datetimepicker1.value

    '" & dat1.ToString("dd/MM/yyyy") & "'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width