By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,570 Members | 970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,570 IT Pros & Developers. It's quick & easy.

Iif/datediff

P: 18
hi
In the below command I like to know can I combine it with the IIf function.
I am checking to see if NSCHD is blank. If it is blank I would place "no date"
in the place of the result..
"Starts In " & DateDiff("d",Format(Date(),"mm/dd"),Format([NSCHD],"mm/dd")) & " Days"


Thanks
bg
Jul 17 '07 #1
Share this Question
Share on Google+
5 Replies


Expert 100+
P: 634
Hi
hi
In the below command I like to know can I combine it with the IIf function.
I am checking to see if NSCHD is blank. If it is blank I would place "no date"
in the place of the result..
"Starts In " & DateDiff("d",Format(Date(),"mm/dd"),Format([NSCHD],"mm/dd")) & " Days"


Thanks
bg
You don't say where you are using this but I thing this would be better, it may even work!

"Starts In " & DateDiff("d",Date(),[NSCHD]) & " Days"

Why format it as you actualy state "Starts in xx Days" and the fuction is set to return days ??

Note days will not format as mm/dd correctly (I believe).

MTB
Jul 17 '07 #2

missinglinq
Expert 2.5K+
P: 3,532
I'd use a simple If...Then construct rather than IIF simply because it's easier to tell at a glance what's going on, and using expressions within IFF can get complicated with hard to spot errors resulting . Also, there's no need to use formatting on your dates in the DateDiff function; you're returning a number of days, not a date. I'd do something like this:

Expand|Select|Wrap|Line Numbers
  1. If IsNull(NSCHD) Then
  2.   "No Date"
  3. Else
  4.   "Starts In " & DateDiff("d",Date,NSCHD) & " Day(s)"
  5. End If
  6.  
Good Luck!

Linq ;0)>
Jul 17 '07 #3

hariharanmca
100+
P: 1,977
hi
In the below command I like to know can I combine it with the IIf function.
I am checking to see if NSCHD is blank. If it is blank I would place "no date"
in the place of the result..
"Starts In " & DateDiff("d",Format(Date(),"mm/dd"),Format([NSCHD],"mm/dd")) & " Days"


Thanks
bg

Yha, you can use it like

Expand|Select|Wrap|Line Numbers
  1. "Starts In " & iif(DateDiff("d",Date,NSCHD) = 0,"No",DateDiff("d",Date,NSCHD)) & " Days"

but if Mike's qurey is workink then you can use that,
Jul 17 '07 #4

missinglinq
Expert 2.5K+
P: 3,532
Didn't mean to step on your toes, Mike! Had to take the dog out between starting and ending my response. Actually the DateDiff will run with the dates formatted, it's just not necessary!

;0)>
Jul 17 '07 #5

Expert 100+
P: 634
Hi missinglinq
Didn't mean to step on your toes, Mike! Had to take the dog out between starting and ending my response. Actually the DateDiff will run with the dates formatted, it's just not necessary!

;0)>
That is not a problem, anything can happen between staring a post and submitting it, and offen does!

I have never tried formatting a date inside DateDiff, had no reason to (yet!), but I will take your word for it.

MTB
Jul 17 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.