Solved

GETDATE()

Posted on 2012-04-02
11
461 Views
Last Modified: 2012-04-02
I am trying to use the GETDATE function in Access and keeping getting an operator error.  Below is the code i thought would work to give me the day difference between current date and LastStarted column.  

SELECT dragon.LastLoginName, dragon.LastStarted, GETDATE() CurrentDateTime, DATEDIFF(day,LastStarted,GETDATE()) As Daydiff
FROM dragon INNER JOIN employeeinfo ON dragon.LastLoginName = employeeinfo.LOGNAME;

I also thought i could just input SELECT GETDATE(); in an access query to get the current date/time, but i also get an error when entering that info.
0
Comment
Question by:jsawicki
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 37796933
To get the current date, use DATE().
To get the current date & time, use NOW()
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 37796967
<no Points Please.>

GetDate() is an SQL function,
In Access use the functions posted by IrogSinta..  ( kumusta kabayan ?)
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 37796985
@capricorn1: (Mabuti naman. Ang galing mo pala dito sa EE.)  I'm impressed!
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 37797010
<@IrogSinta: email me, see my profile for the addy>
0
 

Author Comment

by:jsawicki
ID: 37797059
The change worked, but now everytime i launch the code, it prompts me to enter a date versus performing the calculation automatically.  Why is that and what do i need to do so it just autopopulates.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:jsawicki
ID: 37797067
Also, when i do enter a date, i get an error in the new column so there is something wrong with my code.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 37797072
Could you post your SQL statement so that we could see what's going on?
0
 

Author Comment

by:jsawicki
ID: 37797119
SELECT dragon.LastLoginName, dragon.LastStarted, Now() AS Today, DateDiff([day],[LastStarted],Now()) AS LastUsed
FROM dragon INNER JOIN employeeinfo ON dragon.LastLoginName = employeeinfo.LOGNAME;
0
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 300 total points
ID: 37797156
Your DateDiff function needs to be DateDiff("d", [LastStarted], Now()) to get the difference in number of days.
0
 
LVL 14

Accepted Solution

by:
pteranodon72 earned 100 total points
ID: 37797167
The DATEDIFF function is different in Access as well. The first parameter is a string: "d" for days, "m" for months, "yyyy" for years -- check Access help on DateDiff -- the parameters can be misleading.

SELECT dragon.LastLoginName, dragon.LastStarted, Now() As Today, DATEDIFF("d",LastStarted, Now()) As LastUsed FROM dragon INNER JOIN employeeinfo ON dragon.LastLoginName = employeeinfo.LOGNAME;

HTH,
pT72
0
 

Author Comment

by:jsawicki
ID: 37797245
Thanks all and the explanation on the difference between Access and SQL.  I am learning from a SQL book, but have an older Access book that didn't discuss this function, but good to know the help shows this info.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now