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 then else date formula

Status
Not open for further replies.

wanzek1

Technical User
Jun 13, 2012
79
US
I am struggling with a formula for a fixed width report. Our system puts a default date of 1/0/1900. I have used a variation or this formula in the past and have never had any problems but I haven't ever needed a place holder of eight spaces if the field is 1/0/1900.

if {HRRM.udOrigHireDate} > #1950/01/01# then {HRRM.udOrigHireDate}
else if {HRRM.udOrigHireDate} < #1950/01/01# then space(8)

I got an error message saying a date is required here.

Thanks!
 
I do not believe using the #'s will work for dates in Crystal Reports. There is a date function, I believe it takes the dates in the form mm/dd/yyyy as as string.

I hope this helps.
 
If I take the pound signs out it highlights the 01/01/1950 and says a date is required here.
 
if {HRRM.udOrigHireDate} > date(1950,1,1) then {HRRM.udOrigHireDate}
else if {HRRM.udOrigHireDate} < date(1950,1,1) then space(8)

I changed this using date instead of the # and I still get the same message saying a date is required here.

The problem in the formula is not anything with the dates. It is with the space(8)
 
The problem is that you are mixing the data type results of the if-then-else statement (a string or a date) which won't work. If you want to use a blank string to indicate no date you could use:

Code:
If 	{HRRM.udOrigHireDate} > Date(1950,1,1) 
Then 	ToText({HRRM.udOrigHireDate}, 'dd/MM/yyyy')
Else	''

I don't have access to Crystal to check my syntax so apologies if it isn't quite right. If you need the date in a different format, just change the last part of the "Then" line.

Cheers
Pete
 
That doesn't give me what I need though. I need a place holder for 8 spaces if the field is less than 1/1/1950.
 
i do not have crystal in front of me, but maybe.....

depending on if you are using the date returned as a date in some other location of the report, but you could create a new formula just for the display something like this:

if {HRRM.udOrigHireDate} < dateserial(1950,01,01) then " "
else totext({HRRM.udOrigHireDate},0)
 
In that case, just change the Else statement in my code to a string of 8 spaces.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top