GETDATE() throwing exception

六眼飞鱼酱① 提交于 2020-01-14 07:58:44

问题


I am creating a simple application where i am using MSAccess as database. When i am trying to retrieve the data using below query - i am getting exception undefined function GETDATE()

select *
from tempdata
where dateissue  between DATEADD(MM, DATEDIFF(MM, 0, GETDATE()) - 0 , 0) 
and  DATEADD(MM,         DATEDIFF(MM, 0, GETDATE()) + 1, - 1 )

can't we use the sql inbuilt methods inside c# code ?? if so how do i solve this problem


回答1:


Now that you moved past the first problem (there is no GETDATE() function in Access SQL), you have discovered another problem.

The DateAdd Function requires a "String expression that is the interval of time you want to add" as its first argument, Interval. But you're giving it MM instead:

DATEADD(MM, DATEDIFF(MM, 0, DATE()) - 0 , 0)

I don't understand what interval you're trying to add. If you want to add minutes, use ...

DateAdd('n', ...

If you want to add months, use ...

DateAdd('m', ...

If you want to add days, use ...

DateAdd('d', ...

Note DateDiff() also expects an Interval string argument and the allowable values are the same as those for DateAdd().




回答2:


GETDATE() is not a function inside MSAccess. The equivilant would be:

Now() provides date and time

Date() provides the date

Time() provides the time




回答3:


In MS ACCESS equivalent of GETDATE() is DATE()



来源:https://stackoverflow.com/questions/18668795/getdate-throwing-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!