Millkind
asked on
String to date time
Dim test As DateTime
test = DateTime.Parse(startdate.V alue.Date & " " & stime.Value.TimeOfDay.ToSt ring)
MsgBox(test)
Why does this only show the date and not the time?
test = DateTime.Parse(startdate.V
MsgBox(test)
Why does this only show the date and not the time?
ASKER
Unable to cast object of type 'System.DBNull' to type 'System.IFormatProvider'.
Can you tell me the values of following if you try to print them on screen
startdate.Value.Date
and
stime.Value.TimeOfDay.ToSt ring
startdate.Value.Date
and
stime.Value.TimeOfDay.ToSt
ASKER
9/9/2013
00:00:00
00:00:00
can you try this
Sorry I don't have VB on my current system to test,
Dim test as string
Dim myDateTime as DateTime
test = startdate.Value.Date & " " & stime.Value.TimeOfDay.ToSt ring
myDateTime = DateTime.ParseExact(test, "MM\/dd\/yyyy HH:mm:ss", Nothing)
if above doesn't work then try this
Dim test as string
Dim myDateTime as DateTime
test = startdate.Value & " " & stime.Value
myDateTime = DateTime.ParseExact(test, "MM\/dd\/yyyy HH:mm:ss", Nothing)
Sorry I don't have VB on my current system to test,
Dim test as string
Dim myDateTime as DateTime
test = startdate.Value.Date & " " & stime.Value.TimeOfDay.ToSt
myDateTime = DateTime.ParseExact(test, "MM\/dd\/yyyy HH:mm:ss", Nothing)
if above doesn't work then try this
Dim test as string
Dim myDateTime as DateTime
test = startdate.Value & " " & stime.Value
myDateTime = DateTime.ParseExact(test, "MM\/dd\/yyyy HH:mm:ss", Nothing)
ASKER
String was not recognized as a valid DateTime. For the first one.
The second one won't work because the stime.value will return a date.
The second one won't work because the stime.value will return a date.
Once I will have access to VB I will get back to you. Is this VB or VBA ?
ASKER
vb
Can u please try this
Dim test as string
Dim myDateTime as DateTime
test = startdate.Value.Date & " " & stime.Value.TimeOfDay.ToSt ring
myDateTime = DateTime.ParseExact(test, "M/d/yyyy HH:mm:ss", Nothing)
Console.WriteLine(myDateTi me)
I assume in above the test string will return a value of 9/9/2013 00:00:00
Dim test as string
Dim myDateTime as DateTime
test = startdate.Value.Date & " " & stime.Value.TimeOfDay.ToSt
myDateTime = DateTime.ParseExact(test, "M/d/yyyy HH:mm:ss", Nothing)
Console.WriteLine(myDateTi
I assume in above the test string will return a value of 9/9/2013 00:00:00
ASKER
Nope only returns the date.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Something wrong with your Stime
you can try Stime.Trim() may be null spaces in it causing some issue
you can try Stime.Trim() may be null spaces in it causing some issue
ASKER
That got it. then boiled down to:
patronusageda.SelectComman d.Paramete rs.Add(New SqlParameter("@startdate", DateTime.ParseExact(startd ate.Value. Date & " " & stime.Value.TimeOfDay.ToSt ring, "M/d/yyyy HH:mm:ss", Nothing)))
patronusageda.SelectComman
Great it worked for you !!!
test = DateTime.ParseExact(startd