VB.net mySQL如何在sql查询中使用DateAdd

时间:2016-02-08 05:17:24

标签: mysql vb.net

我在表单加载时遇到错误并且表示FUNCTION databasename.DateAdd不存在

con.Open()
cmd.Connection = con
cmd.CommandText = "update pawn set status = 'Renewed', date_added = DateAdd(month,4,date_added), first_date = DateAdd(month,5,first_date), second_date = DateAdd(month,6,second_date), due_date = DateAdd(month,7,due_date)"
dr = cmd.ExecuteReader
con.Close()

2 个答案:

答案 0 :(得分:1)

您在查询中使用了VB.NET的DateAdd(),这对MySQL不起作用,因为MySQL没有像这样的内置函数

MySQL date add 函数的语法为DATE_ADD(date,INTERVAL expr type)

   cmd.CommandText = "update pawn set status = 'Renewed' " & _
                     ",date_added = DATE_ADD(date_added,INTERVAL 4 MONTH)" & _
                     ",first_date = DATE_ADD(first_date,INTERVAL 5 MONTH)" & _
                     ",second_date = DATE_ADD(second_date,INTERVAL 6 MONTH)" & _
                     ",due_date = DATE_ADD(due_date,INTERVAL 7 MONTH)"

答案 1 :(得分:1)

您可以执行以下操作 -

ADDDATE(date_column, INTERVAL 4 YEAR)
ADDDATE(date_column, INTERVAL 4 MONTH)
ADDDATE(date_column, INTERVAL 4 DAY)