7 Replies Latest reply on Apr 21, 2016 6:36 AM by alecgregory

# Can some one explain less than or more than with dates?

I have recently become VAT registered as of the first of the month so I have had to change my invoices to add vat where applicable.

first this is my understanding of the if statement:

if(x; do this ;otherwise do this)

I wrote a line of code:

If (end_date  >  1/4/2016; net_invoice_total *  (Clients::client_vat_rate) ; 0 )

end date is the invoice date. I want to, for all invoices after (greater than) 1/4/16, to work out the VAT, other wise it's zero.

however the above didn't work, it worked out the VAT for all invoices before the date and not after.

so I changed the inequality signs round so

If (end_date  <  1/4/2016; net_invoice_total *  (Clients::client_vat_rate) ; 0 )

this works but I'm confused as my understanding is:  earlier date < Later date, 1<4 , 1/4/16<2/4/16

Paul

• ###### 1. Re: Can some one explain less than or more than with dates?

Use a proper date, not a string:

Case (

end_date > Date ( 4 ; 1 ; 2016 ) ;

net_invoice_total * Clients::client_vat_rate

)

• ###### 2. Re: Can some one explain less than or more than with dates?

1/4/2016 is 1 / 4 / 2016 = 0000.124

Use GetAsDate ( "1/4/2016" ) or Date ( 1; 4; 2016 ) to define your date

So

If (end_date  >  Date ( 1; 4; 2016 ); net_invoice_total *  (Clients::client_vat_rate) ; 0 )

Edit Not sure if you're talking April or January. But the Date function parameter order is Date ( Month; Day; Year )

• ###### 3. Re: Can some one explain less than or more than with dates?

erolst wrote:

Use a proper date, not a string:

Case (

end_date > Date ( 4 ; 1 ; 2016 ) ;

net_invoice_total * Clients::client_vat_rate

)

I don't think that will give a zero if the date is before 1/4/2016. No need for Case either, the OP can stick with If.

• ###### 4. Re: Can some one explain less than or more than with dates?

Can not believe I didn't think of that. just had a real kick myself moment:-)

thank you both for getting back to me so soon

• ###### 5. Re: Can some one explain less than or more than with dates?

alecgregory wrote:

I don't think that will give a zero if the date is before 1/4/2016.

Of course it doesn't – it returns <nothing>, which for the purpose of addition is equivalent …

alecgregory wrote:

No need for Case either, the OP can stick with If.

Why think about whether to use If() or Case() if the latter one is always appropriate?

• ###### 6. Re: Can some one explain less than or more than with dates?

Don't kick yourself. This forum is all about getting out of trouble and getting on with the task ahead. :-)

• ###### 7. Re: Can some one explain less than or more than with dates?
Of course it doesn't – it returns <nothing>, which for the purpose of addition is equivalent …

But wouldn't look as nice as a zero on a printed invoice...

Why think about whether to use If() or Case() if the latter one is always appropriate?

That's a good question. Appropriate, eh? That's a loaded word. I have a (probably definitely irrational) hatred of the Case function because:

1) It encourages slapdash logic with the potential for inefficiencies
With Case you don't need to think through logic as much and as a result it encourages inefficient coding. A poorly thought-out Case statement can often be replaced with an If or nested-If statement that is clearer, more succinct and explains the business logic more accurately

2) It is not necessary, ever.

Sure, I use Case for readability, but there's nothing a Case can accomplish that an If or nested-If can't. If we're interested in readability I think If-ElseIf would be a much better structure to have in the FileMaker calculation engine. We have it in scripting, why not be consistent? Note: I know If-ElseIf isn't really feasible in a functional programming language like the FileMaker calculation engine, but see above regarding rationality.

3) It's non-standard and confusing

I have never encountered Case used in the FileMaker manner in any other language. This wouldn't be so bad in itself, but it can also get confused with the Switch function, which is common in other programming languages. FileMaker sort of has its own version of the Switch function, but it's called Choose, only works with numbers and no one has ever used it.

#### 4) It just sucks, OK?

Go back to your Switch expression Case. Don't get ideas above your station. Etc. Etc.