A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

IIF statement using dates



 
 
Thread Tools Display Modes
  #1  
Old February 26th, 2009, 04:21 PM posted to microsoft.public.access.gettingstarted
[email protected]
external usenet poster
 
Posts: 1
Default IIF statement using dates

Can anyone help please?

I am using the following formula to try and tell me if an entry is
greater than a certain date:

IIf([Completion Date]1/1/2008,"YES","NO")

However, regardless of the "Completion Date", the formula always
returns "YES". Is this because it isn't recognising it as a date?

Any help would be much appreciated!

Mark
  #2  
Old February 26th, 2009, 04:31 PM posted to microsoft.public.access.gettingstarted
Steve[_57_]
external usenet poster
 
Posts: 598
Default IIF statement using dates

Hello Mark,

Dates always need to be enclosed in #s. Without the #s Access thinks your
date expression is division. Try this:
IIf([Completion Date]#1/1/2008#,"YES","NO")

Steve




wrote in message
...
Can anyone help please?

I am using the following formula to try and tell me if an entry is
greater than a certain date:

IIf([Completion Date]1/1/2008,"YES","NO")

However, regardless of the "Completion Date", the formula always
returns "YES". Is this because it isn't recognising it as a date?

Any help would be much appreciated!

Mark



  #4  
Old February 26th, 2009, 05:09 PM posted to microsoft.public.access.gettingstarted
John W. Vinson
external usenet poster
 
Posts: 18,261
Default IIF statement using dates

On Thu, 26 Feb 2009 16:35:47 GMT, "Software-Matters via AccessMonster.com"
u49864@uwe wrote:

Try this:

iif(DateDiff ('d', #01/01/2008#,[Completion Date]) 1,"YES","NO")

Actually just had another thought. Check your date format i.e. dd/mm/yyyy or
mm/dd/yyyy etc this can sometimes have a funny effect on dates.


to amplify... if you use a literal date such as #3/2/2009# Access will always
interpret it in American form, month-day-year (March 2). This is the case even
if your regional settings are in the (admittedly more logical) day-month-year
form.

Mark, if your intent is to compare the completion date to the first day of the
current year (whenever the query is run), you should use the current year
explicitly rather than a literal date:

Iif([Completion Date] DateSerial(Year(Date()), 1, 1), "this year", "earlier
year")
--

John W. Vinson [MVP]
  #5  
Old February 26th, 2009, 06:39 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default IIF statement using dates

"John W. Vinson" wrote in message
...
On Thu, 26 Feb 2009 16:35:47 GMT, "Software-Matters via AccessMonster.com"
u49864@uwe wrote:

Try this:

iif(DateDiff ('d', #01/01/2008#,[Completion Date]) 1,"YES","NO")

Actually just had another thought. Check your date format i.e. dd/mm/yyyy
or
mm/dd/yyyy etc this can sometimes have a funny effect on dates.


to amplify... if you use a literal date such as #3/2/2009# Access will
always
interpret it in American form, month-day-year (March 2). This is the case
even
if your regional settings are in the (admittedly more logical)
day-month-year
form.


picky
Except for days of 13 or higher.

In other words, #12/01/2009# will ALWAYS be interpretted as 01 Dec, 2009,
whereas as #13/01/2009# will be interpretted as 13 Jan, 2009.
/picky

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.