我想使用vb.net在mysql表中插入一个字符串作为日期格式。我在下面给出了代码。但我总是收到错误。字符串存储在一个数组中。
mycode
------
Dim sdfsa As String = Convert.ToDateTime(newarray(i + 17)).ToShortDateString().ToString("yyyy-MM-dd")
Dim newdate As Date = DateTime.ParseExact(sdfsa, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture)
datarw("date_of_birth") = newdate
答案 0 :(得分:0)
答案 1 :(得分:0)
试试这个:
my_date =Format(Now,"yyyy-MM-dd")
答案 2 :(得分:0)
示例
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim year, month, day As Integer
Dim date_value As Date
Dim date_final_to_mySQL As String
date_value = DateTimePicker1.Value
year = date_value.Year
month = date_value.Month
day = date_value.Day
date_final_to_mySQL = year & "-" & month & "-" & day
MessageBox.Show(date_final_to_mySQL)
End Sub
只需创建一个button1和datetimepicker1