×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Derived field based on subtracting 2 dates and if 0 add 1

Derived field based on subtracting 2 dates and if 0 add 1

Derived field based on subtracting 2 dates and if 0 add 1

(OP)
Derived Field value based on subtracting to dates and if the value is zero then return a 1 else return the value from subtracting the two dates.

Code :
Sub DateDiff()
If "FAX_DATE" - "INPUTDATE" = 0 Then
DerivedField(1)
Else
DerivedField(("FAX_DATE") - ("INPUTDATE"))
End If
End

ERROR is illegal arguments to subtract

I'm new to this. Any help would be appreciated

RE: Derived field based on subtracting 2 dates and if 0 add 1

You don't need to use a macro for this.  Use a SQL Derived Field like this:

DECODE(("tablename"."FAX_DATE" - "tablename"."INPUTDATE"),
             0,1,
            ("tablename"."FAX_DATE" - "tablename"."INPUTDATE"))

What this is saying is:

IF ("tablename"."FAX_DATE" - "tablename"."INPUTDATE") = 0
THEN
     1
ELSE
     ("tablename"."FAX_DATE" - "tablename"."INPUTDATE")
END IF


As far as your macro goes I think this would be closer:

Sub DateDiff()

FaxDate = DateValue(Field$("FAX_DATE"))
InputDate = DateValue(Field$("INPUTDATE"))
DateDiff = (FaxDate - InputDate)

If DateDiff = 0 Then
     DerivedField "1"
Else
     DerivedField Str$(DateDiff)
End If

End

http://CharlesCook.com
Specializing in ReportSmith Training and Consulting

RE: Derived field based on subtracting 2 dates and if 0 add 1

How did that work out for you?

http://CharlesCook.com
Specializing in ReportSmith Training and Consulting

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close