Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GETDATE() throwing exception

Tags:

ms-access

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

like image 840
New Coder Avatar asked Sep 07 '13 01:09

New Coder


People also ask

What does getdate() function of php return?

The getdate() function returns date/time information of a timestamp or the current local date/time.

What does Getdate () function do?

The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format.

What type is Getdate () SQL?

GETDATE is a nondeterministic function.

How to use getdate() in php?

Example of PHP getdate() function php $today=getdate(); echo "The Day of month = ". $today['mday'] . "<br>"; echo "Day of week = ". $today['wday'] .


2 Answers

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

Now() provides date and time

Date() provides the date

Time() provides the time

like image 65
maccettura Avatar answered Oct 16 '22 09:10

maccettura


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().

like image 4
HansUp Avatar answered Oct 16 '22 11:10

HansUp