DateDiff & 30 days

J

James

I'm trying to add a field to a query that would find the difference between
two dates and some math like:

Serv_ch:(((( DateDiff("d",Now() - [OrderDate]))/30)-1)*.015)

To derive the number of 30 day intervals from OrderDate to Current date,
subtract 1, then multiply the remaining integer * 0.015
My syntax has an error I can't resolve.

Any suggestions appreciated.
 
K

KARL DEWEY

Better to use Mod function.

Serv_ch: ((DateDiff("d",Now() - [OrderDate])Mod 30)-1) *.015
 
M

Michel Walsh

You give the two dates, you don't subtract them, yourself.

The earliest date is the first one.

Unless you want fractional intervals, use INT, or other integer-rounding.

Try:

Serv_ch: (((Int( DateDiff("d", [OrderDate], Now() ))/30)-1)*.015)



Hoping it may help,
Vanderghast, Access MVP
 
M

Michel Walsh

You probably meant integer division, \


Vanderghast, Access MVP


KARL DEWEY said:
Better to use Mod function.

Serv_ch: ((DateDiff("d",Now() - [OrderDate])Mod 30)-1) *.015

--
KARL DEWEY
Build a little - Test a little


James said:
I'm trying to add a field to a query that would find the difference
between
two dates and some math like:

Serv_ch:(((( DateDiff("d",Now() - [OrderDate]))/30)-1)*.015)

To derive the number of 30 day intervals from OrderDate to Current date,
subtract 1, then multiply the remaining integer * 0.015
My syntax has an error I can't resolve.

Any suggestions appreciated.
 
J

James

Your line using Mod throws a "wrong number of arguments" error on save.

Michel Walsh's line is accepted without error, but I'm looking to see why it
returns no result.

KARL DEWEY said:
Better to use Mod function.

Serv_ch: ((DateDiff("d",Now() - [OrderDate])Mod 30)-1) *.015

--
KARL DEWEY
Build a little - Test a little


James said:
I'm trying to add a field to a query that would find the difference
between
two dates and some math like:

Serv_ch:(((( DateDiff("d",Now() - [OrderDate]))/30)-1)*.015)

To derive the number of 30 day intervals from OrderDate to Current date,
subtract 1, then multiply the remaining integer * 0.015
My syntax has an error I can't resolve.

Any suggestions appreciated.
 
J

James

Correction, result IS visible in query.
Not making it to my report. Its Me.
Sorry.

James said:
Your line using Mod throws a "wrong number of arguments" error on save.

Michel Walsh's line is accepted without error, but I'm looking to see why
it returns no result.

KARL DEWEY said:
Better to use Mod function.

Serv_ch: ((DateDiff("d",Now() - [OrderDate])Mod 30)-1) *.015

--
KARL DEWEY
Build a little - Test a little


James said:
I'm trying to add a field to a query that would find the difference
between
two dates and some math like:

Serv_ch:(((( DateDiff("d",Now() - [OrderDate]))/30)-1)*.015)

To derive the number of 30 day intervals from OrderDate to Current date,
subtract 1, then multiply the remaining integer * 0.015
My syntax has an error I can't resolve.

Any suggestions appreciated.
 
J

James

I have a follow up question relating to this...

When my number of days is less than 30, I'm trying to set the Serv_ch value
to 0 or 1

as follows:
Serv_ch: IIf(DateDiff("d",[OrderDate],Now()))>30
(((Int(DateDiff("d",[OrderDate],Now()))/30)-1)*0.015), 0

I'm getting a "wrong number of arguments though, any suggestions?

James said:
Correction, result IS visible in query.
Not making it to my report. Its Me.
Sorry.

James said:
Your line using Mod throws a "wrong number of arguments" error on save.

Michel Walsh's line is accepted without error, but I'm looking to see why
it returns no result.

KARL DEWEY said:
Better to use Mod function.

Serv_ch: ((DateDiff("d",Now() - [OrderDate])Mod 30)-1) *.015

--
KARL DEWEY
Build a little - Test a little


:

I'm trying to add a field to a query that would find the difference
between
two dates and some math like:

Serv_ch:(((( DateDiff("d",Now() - [OrderDate]))/30)-1)*.015)

To derive the number of 30 day intervals from OrderDate to Current
date,
subtract 1, then multiply the remaining integer * 0.015
My syntax has an error I can't resolve.

Any suggestions appreciated.
 
J

James

I think I have it working, counting the number of 30 day periods after the
initial 30 days from OrderDate.
If its less than 30 days, it sets my Serv_ch =0

Serv_ch:
IIf(DateDiff("d",[OrderDate],Now())>30,(((Int(DateDiff("d",[OrderDate],Now()))/30)-1)*0.015),0)

James said:
I have a follow up question relating to this...

When my number of days is less than 30, I'm trying to set the Serv_ch
value to 0 or 1

as follows:
Serv_ch: IIf(DateDiff("d",[OrderDate],Now()))>30
(((Int(DateDiff("d",[OrderDate],Now()))/30)-1)*0.015), 0

I'm getting a "wrong number of arguments though, any suggestions?

James said:
Correction, result IS visible in query.
Not making it to my report. Its Me.
Sorry.

James said:
Your line using Mod throws a "wrong number of arguments" error on save.

Michel Walsh's line is accepted without error, but I'm looking to see
why it returns no result.

Better to use Mod function.

Serv_ch: ((DateDiff("d",Now() - [OrderDate])Mod 30)-1) *.015

--
KARL DEWEY
Build a little - Test a little


:

I'm trying to add a field to a query that would find the difference
between
two dates and some math like:

Serv_ch:(((( DateDiff("d",Now() - [OrderDate]))/30)-1)*.015)

To derive the number of 30 day intervals from OrderDate to Current
date,
subtract 1, then multiply the remaining integer * 0.015
My syntax has an error I can't resolve.

Any suggestions appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Can't query DateDiff 3
Help with Query syntax 2
DateDiff returning incorrect years 11
datediff problem 3
CalcWorkDays error 1
Projected Business Days 1
DateDiff function 3
Help with small result type 2

Top