Click to See Complete Forum and Search --> : Concatenating strings to be a Date value


Ciralia
March 17th, 2006, 10:30 AM
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:

Dim birthDate As Date

birthDate = (Month + "/" + Day + "/" + Year)

But this code doesn't work.

vbArch
March 17th, 2006, 11:15 AM
look at the overload method 2 of the date
Dim birthDate As New Date(val(Year), val(Month), val(Day))

Ciralia
March 17th, 2006, 01:58 PM
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?

vbArch
March 17th, 2006, 02:12 PM
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)

Ciralia
March 20th, 2006, 08:08 AM
Thank you I did get it to work =)