CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2006
    Posts
    94

    Arrow Concatenating strings to be a Date value

    If I have 3 strings: Day, Month, Year (i.e. "01", "10", "1980")

    How do I concatenate these strings so that they can be recognized as a Date type with formating mm/dd/yyyy. I can change them to be integers if needed. I'm thinking something along the lines of:

    Code:
    Dim birthDate As Date
    
    birthDate = (Month + "/" + Day + "/" + Year)
    But this code doesn't work.

  2. #2
    Join Date
    Mar 2006
    Posts
    16

    Smile Re: Concatenating strings to be a Date value

    look at the overload method 2 of the date
    Dim birthDate As New Date(val(Year), val(Month), val(Day))

  3. #3
    Join Date
    Mar 2006
    Posts
    94

    Re: Concatenating strings to be a Date value

    This would probably work, except that in my MS Access database the Date field is formated like mm/dd/yyyy. I forgot to mention before that I was sending this date to be stored in a database.

    So that code is giving me an error because it doesn't match the format I think. How do I make it this format, and do I do this during the creation of the birthDate variable?
    Last edited by Ciralia; March 17th, 2006 at 03:02 PM.

  4. #4
    Join Date
    Mar 2006
    Posts
    16

    Smile Re: Concatenating strings to be a Date value

    Not quite sure I understand the problem this code shows how to do it with 3 strings for month,day, year and the second just sets a date for a string date

    Dim d As String = "15"
    Dim m As String = "01"
    Dim y As String = "2000"
    Dim ds As String = "01/15/2000"
    Dim birthdate As New Date(CInt(y), CInt(m), CInt(d))
    Dim birthdate1 As Date = CDate(ds)

    Console.Write(birthdate.ToShortDateString)
    Console.Write(birthdate1.ToShortDateString)

  5. #5
    Join Date
    Mar 2006
    Posts
    94

    Re: Concatenating strings to be a Date value

    Thank you I did get it to work =)

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

Featured