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!

Dealing with a null date - to get a MonthName

Status
Not open for further replies.

davida37

IS-IT--Management
May 10, 2006
113
GB
I fI set a date value to null - I was hoping the last 2 would deal with it. I have tired everything and still just get a blank field on my report. Help please!

Thanks


If month(DateAdd ("m", -1, {?@date})) = 1 Then
'January'
else If month(DateAdd ("m", -1, {?@date})) = 2 Then
'February'
else If month(DateAdd ("m", -1, {?@date})) = 3 Then
'March'
else If month(DateAdd ("m", -1, {?@date})) = 4 Then
'April'
else If month(DateAdd ("m", -1, {?@date})) = 5 Then
'May'
else If month(DateAdd ("m", -1, {?@date})) = 6 Then
'June'
else If month(DateAdd ("m", -1, {?@date})) = 7 Then
'July'
else If month(DateAdd ("m", -1, {?@date})) = 8 Then
'August'
else If month(DateAdd ("m", -1, {?@date})) = 9 Then
'September'
else If month(DateAdd ("m", -1, {?@date})) = 10 Then
'October'
else If month(DateAdd ("m", -1, {?@date})) = 11 Then
'November'
else If month(DateAdd ("m", -1, {?@date})) = 12 Then
'December'
else If month({?@date}) = 0 Then
'this dosesnt work'
//MonthName(month(DateAdd ("m", -1, CurrentDate)))
else
'this dosesnt work'
 
Whenever Crystal hits a null, it stops. You should begin with
Code:
if isnull(DateAdd) then 
"Null Date"
else
I suspect that, like me, you have come to Crystal from Mainframe. Null was one of the things that confused me a lot. Another was 'divide by zero' - Crystal stops and every division should be tested for zero first. As for dates, Crystal stores dates in its own format, so I don't think a month of zero would be possible.


[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Simplify:

if isnull({?MyDateParm}) then
"null date"
else
monthname(month(dateadd("m",-1,{?MyDateParm})))

-k
 
thanks both very much. I didnt know crystal checks for nulls first or this is best practice. I will from now on!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top