Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Statement

Status
Not open for further replies.

metalteck

MIS
May 10, 2006
54
US
Crystal 8.5
I have 2 formulas that will tell me the difference of days between them.

date({@Discharge Date}-{@ADM})

ADM DD Stay
7/25/06 7/26/06 02
1/13/06 30


I changed the format options to a custom, so that it would only show me the number of days.When I display this information, the information is correct. The only problem is that if DischargeDate does not have a value, the value of stay is 30. I would like this value to be 0, if there is no value for discharge. Can someone help.

Thank you

Chris
 
Nothing here makes sense, and please don't reference formulas that you don't supply the code for.

You example shows 7/26 - 7/25 = 2, which should be 1.

And what does changing format options have anything to do with this?

Let's avoid the unknowns for a moment and give you an example:

cdate(2006,7,26)-cdate(2006,7,25) will return 1.

So whatever you're doing in your formulas are probably affecting this, OR some odd adjustment to formatting.

So if you want the difference in days you an just use:

{table.date1}-{table.date2}

It won't show 30 for null date, but again I don't know what's in the formula you used so I can't help with that. I never understand why people think that code has nothing to do the solution.

If you have a concern with nulls in a date, then use this formula:

if isnull({table.date1})
or
isnull({table.date2}) then
0
else
{table.date1}-{table.date2}

-k
 
Here are what the formulas look like:
ADM = Date ({BADPLPP.LPADT3},{BADPLPP.LPADT1} ,{BADPLPP.LPADT2} )

DischargeDate=
stringvar MyDate := totext({badplpp.lpldd},0,"");
if len(MyDate) = 5
then
cdate(2000+val(right(MyDate,2)), val(left(MyDate,1)),val(mid(MyDate,2,2)))
else
if len(MyDate) = 6
then
cdate(2000+val(right(MyDate,2)), val(left(MyDate,2)),val(mid(MyDate,3,2)))

when I use the formula: ({@Discharge Date}-{@ADM}, when Discharge Date has no value, it returns a 0. The other values are different. For example...

ADM DD Stay
7/20/06 7/20/06 730487

Can you help me in getting it to say 1.

Thank you
 
Format your dates to show the years, it looks like you are producing bad years in one of the date fields, your off by about 2001 days.

I don't have examples of the data so I can't help you.

-k
 
If I use the formula: ({@Discharge Date}-{@ADM}, it results with the number 730487 and is a number type.

If I use the formula: date({@Discharge Date}-{@ADM}, the results are in date format, with the year showing. Ex:1/1/00

How can I only show the difference between days?
 
If you don't want to try what people suggest why bother posting?

I knew what the 730487 stood for, it's showing you the difference in days, and since it's about 2000 years off (I incorrectly stated days before), one of your dates is being computed incorrectly, and if you would simply test the YEAR of your computed dates rather than repeating the same thing and expecting a different result you'd have corrected this by now.

Place your date formulas in the details, right click them and select format field and select a format which shows the year.

You don't supply examples of the data, so we cannot test for you, and the problem looks obvious to me, so please test PRIOR to posting again and share the results.

-k
 
I see the problem that you were saying. In the formula:
ADM = Date ({BADPLPP.LPADT3},{BADPLPP.LPADT1} ,{BADPLPP.LPADT2} )

the year field, LPADT3 is only 1 character long. So when I'm trying to do the difference, you are correct, it is off by 2000 years.

Here is some of the data being represented:
ADM DD Stay
07/20/6 7/20/06 01/01/3900
01/13/6 12/30/1899
07/21/6 7/22/06 01/02/3900

How can I fix this?
 
Since the year field is wrong, you may need to add 2000 to it as well?

As in:

whileprintingrecords;
datevar ADM;
if {BADPLPP.LPADT3} < 1900 then
ADM := Date (2000+{BADPLPP.LPADT3},{BADPLPP.LPADT1} ,{BADPLPP.LPADT2} )
else
ADM := Date ({BADPLPP.LPADT3},{BADPLPP.LPADT1} ,{BADPLPP.LPADT2})

-k
 
Thank you for all your help. This works perfectly. And in the future I will try to be a little more clear and specific.

Thank you again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top