Solved

GETDATE()

Posted on 2012-04-02
11
471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

636 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