Try
DateTimePicker1.Format = DateTimePickerFormat.Custom
' Display the date as "2012-10-24 21:47:09".
DateTimePicker1.CustomFormat = "yyyy-MM-dd HH:mm:ss"
strQuery = "INSERT INTO TimeClockInfo(IdTimeClock, First_Name, Last_Name, LogTime, In_Out) VALUES('" & AddTimeEmplyIdBox.Text & "','" & AddTimeEmplyFNBox.Text & "','" & AddTimeEmplyLNBox.Text & "','" & DateTimePicker1.Value & "','in')"
SQLCmd = New MySqlCommand(strQuery, dbCon)
dbCon.Open()
SQLCmd.ExecuteNonQuery()
dbCon.Close()
MsgBox("TimeClock Data Added Successfully!")
Catch ex As Exception
MsgBox("Failure!", ex.Message)
End Try
this returns the original format of the date and time in the value property? what am i doing wrong here?
DateTimePicker1.Valueis aDateTime– it doesn’t have an inherent format.If you want to format it, use
ToStringwith a Date and Time format string of your choice.MSDN details the standard and custom format strings.
However, since you are interacting with SQL, you shouldn’t be concatenating SQL – your code is open to SQL Injection this way. You should use parameterized SQL, which doesn’t have this vulnerability and will deal with the
DateTimecorrectly as well.