Results 1 to 10 of 10

Thread: how to convert string to date in vb.net

  1. #1

    Thread Starter
    Lively Member sandin's Avatar
    Join Date
    Nov 2001
    Location
    From Your Heart!!!!
    Posts
    68

    Lightbulb how to convert string to date in vb.net

    hi guys

    i waant to know how to convet the string to date in vb.net ..
    i fany body have code please let me know...

    sandin

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    there is a CDate() function
    there is probably a better way though
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Lively Member sandin's Avatar
    Join Date
    Nov 2001
    Location
    From Your Heart!!!!
    Posts
    68
    hi MrPolite

    i used that but it doen`t work properly.. could u give me the sample code for easy understanding..

    sandin

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Try this
    VB Code:
    1. DateTime.Parse("december 12, 2005").ToShortDateString()
    Dont gain the world and lose your soul

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object _
    2.     , ByVal e As System.EventArgs) Handles MyBase.Load
    3.         Dim datetime As DateTime = Now.Today
    4.         'string date
    5.         MsgBox(datetime.ToString)
    6.         'string date converted to date type
    7.         MsgBox(CDate(datetime))
    8.     End Sub

  6. #6

    Thread Starter
    Lively Member sandin's Avatar
    Join Date
    Nov 2001
    Location
    From Your Heart!!!!
    Posts
    68
    hi guy,

    if my string is "20021212" then i want to convert it in Date format

    will u plz. tell ?? how??

    sandin

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    is your string always fix-string ??inother words , it contains 8 chara ?

  8. #8

    Thread Starter
    Lively Member sandin's Avatar
    Join Date
    Nov 2001
    Location
    From Your Heart!!!!
    Posts
    68
    yes , it is 8 chat and a number..

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Look at the string in the code and after msgbox is shwon , this means it's converted to date type.

    VB Code:
    1. Dim datetime As String = "20021213"
    2.         datetime = datetime.Insert(4, "/")
    3.         MsgBox(CDate(datetime.Insert(7, "/")))

  10. #10
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You might have to write your own function to convert that format or you can change the format to 2002/12/12, then you can use
    VB Code:
    1. MessageBox.Show(DateTime.Parse("2002/12/12").ToLongDateString())
    Dont gain the world and lose your soul

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