Date function query

Nunzie23

Board Regular
Joined
Feb 22, 2007
Messages
152
HI! Thanks in advance to anyone who can offer some help with this.

In a very simple database I have a field (referral date) and another one (1st appointment) which I need a calculation for. Basically I want to create an additional field that tells me in months and days how long a person was waiting between the date they were referred and the date of the 1st appointment.

If they actually haven't received a 1st appointment yet and the 1st appointment field is blank I would like it to calculate the waiting time so far with the the current date.

I think it's something like [1st appointment] - [referral date] but i'm not sure how to add the if function if the 1st appointment field is blank. And do I put this in the query itself? or in the report, etc.

Thanks again for the help.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Ok...so I see how to use the date difference function to give me the number of days if I have a date in the two fields(date of referral field and date of appt field), but I'm not sure how I get it to give me the number of days if the appt date field is blank and I want it to use the current date.

I'm sorry if the answer is there and I just don't understand it as I'm not very familiar with these formulas and doing these functions...this is my first database.
 
Upvote 0
Ok. Try this
Code:
=iif([1st Appointment]="",datediff("d",date(),[referral date]),datediff("d",[1st Appointment],[Referral date]))

Alan
 
Upvote 0
Ok.........so I put this in the query design....

Expr1: if([Date of 1st Appt]="",DateDiff("d",Date(),[Date of Referral]),DateDiff("d",[Date of1st Appt],[Date of Referral]))

I get an error message that says:

Undefined function 'if' in expression.

What am I doing wrong?

I'm soooo sorry I'm not getting this and if I'm making something very simple more difficult than it needs to be.
 
Upvote 0
Need to make the statement with two i's. =IIF as in Immediate If

Alan
 
Upvote 0
It gives me a negative number where there are both dates (-34) but if there is no date in the 1st appt field it is blank. Not calculating by the current date.
 
Upvote 0
Swap the order of the date fields in the DateDiff function.


Alan
 
Upvote 0
Thanks Alan, works perfectly for giving me the number of days waiting provided there is a date in both the date of referral and date of 1st appt field. But it doesn't give me a days waiting if there is no date in 1st appt.

Just to see if I've done something else wrong below is the current expression:

Expr1: IIf([Date of 1st Appt]="",DateDiff("d",Date(),[Date of 1st Appt]),DateDiff("d",[Date of Referral],[Date of 1st appt]))

So basically I want it to give me for those with blank 1st appts how long they have been waiting from the date of referral until today(current date).
 
Upvote 0
And Alan, I really appreciate all your help. I know this is probably annoying to you as someone who grasps all this and can get their head around it all. I'm probably struggling with something that is quite basic.

:)
 
Upvote 0

Forum statistics

Threads
1,224,612
Messages
6,179,890
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top