Date Add Query confusing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

PERCENT:
IIf(Now()<DateAdd("yyyy",+1,[HPDATE]),"4%",IIf(Now()<DateAdd("yyyy",+2,[HpDate]),"5%",Null))

2PERCENT:IIF(NOW()<DATEADD("YYYY"+7,
[HPDATE]),"7%",IIF(NOW()<DATEADD("YYYY",+15, [HPDATE]),"9%",NULL))

Can anyone please explain to me the difference in these two lines. The
first one runs fine, the second tells me it wrong and will not work. I had
them combined but it still would not run and kept getting hung on the +7. I
cannot see what I have done wrong but I am sure it's something simple. Thanks
 
PERCENT:
IIf(Now()<DateAdd("yyyy",+1,[HPDATE]),"4%",IIf(Now()<DateAdd("yyyy",+2,[HpDate]),"5%",Null))

2PERCENT:IIF(NOW()<DATEADD("YYYY"+7,
[HPDATE]),"7%",IIF(NOW()<DATEADD("YYYY",+15, [HPDATE]),"9%",NULL))

Can anyone please explain to me the difference in these two lines. The
first one runs fine, the second tells me it wrong and will not work. I had
them combined but it still would not run and kept getting hung on the +7. I
cannot see what I have done wrong but I am sure it's something simple. Thanks

The first has a comma between "yyyy" and +1. The second does not have
the (required) comma between "YYYY" and +7.

Note that you can leave the + off; it's not needed, since +7 and 7 are
the same number. Also, Now() is NOT today's date; it's the current
date and time accurate to microseconds. You might want to use Date()
instead.

John W. Vinson[MVP]
 
Thank you knew it had to be something simple.

John Vinson said:
PERCENT:
IIf(Now()<DateAdd("yyyy",+1,[HPDATE]),"4%",IIf(Now()<DateAdd("yyyy",+2,[HpDate]),"5%",Null))

2PERCENT:IIF(NOW()<DATEADD("YYYY"+7,
[HPDATE]),"7%",IIF(NOW()<DATEADD("YYYY",+15, [HPDATE]),"9%",NULL))

Can anyone please explain to me the difference in these two lines. The
first one runs fine, the second tells me it wrong and will not work. I had
them combined but it still would not run and kept getting hung on the +7. I
cannot see what I have done wrong but I am sure it's something simple. Thanks

The first has a comma between "yyyy" and +1. The second does not have
the (required) comma between "YYYY" and +7.

Note that you can leave the + off; it's not needed, since +7 and 7 are
the same number. Also, Now() is NOT today's date; it's the current
date and time accurate to microseconds. You might want to use Date()
instead.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top