# Date Calculation

## Recommended Posts

I would like to create a calculation field that evaluates the contents of a Date field and based on what's found in that field, return a 1,2,3, or 4. The database I'm modifying has 10k records and I've been asked to provide "Marking Period" information. For example, a date between 9/1/2002 and 11/10/2002 should give me a 1 and a date between 11/11/2002 and 1/27/2003 should give me a 2. The year isn't important, just the month and day.

Thanks!

##### Share on other sites

Your example is not enough to go on. Are the boundary dates tha same Month/Day every year? And what are they?

##### Share on other sites

If the year is not a factor you could use a calc DayOfYear(date) and then an if or case statement. If you don't understand I'll post a sample. I use something like this for special pricing.

John

##### Share on other sites

DayOfYear() is problematic especially if the year is not a factor. For example, Sep 1 is day 244 this year, but 245 on a leap year.

##### Share on other sites

The boundary dates are the same every year. And for this particular function, the year is unimportant. I'll take a look at the DayOfYear() function in the mean time.

1. 9/1 - 11/10

2. 11/11 - 1/27

3. 1/28 - 4/7

4. 4/8 - 6/23

Ultimately, I'd like to set up radio buttons to allow users to search by marking period.

Thanks for your responses! It gives me something to go on-

##### Share on other sites

Try something like:

Let ( [

dec = Month ( Date ) + Day ( Date ) / 100

] ;

Case (

dec > 11.1 ; 2 ;

dec > 8.31 ; 1 ;

dec > 6.23 ; 0 ;

dec > 4.07 ; 4 ;

dec > 1.27 ; 3 ;

2

)

)

Since you have a hole in your periods (summer break?), I had to provide an arbitrary result of 0 for the missing range - you can change that to empty string or "n/a" or whatever you like.

##### Share on other sites

Comment

I never thought of that. I change my fixed date to day of year and then do a range search. I guess that's why.

John

##### Share on other sites

Comment,

Yes, the 'hole' you refer to is for summer break. And thank you both very much for your suggestions. As soon as I get back to THAT particular database, I'll try the 'Let' function. I've never used that one before, so it will be interesting to give that a shot. I'll let you know how it works...

Again, thanks for your help!

##### Share on other sites

what if the year is important?

##### Share on other sites

Then it needs to be accounted for. Can you be more specific?

##### Share on other sites

What I'm tying to do is something like:

if(1/1/2004≤Date≤3/31/2004; "Q1")

if(4/1/2004≤Date≤6/30/2004; "Q2")

at etc....

I've somehow accomplished this in the past, but can't seem to get it right now... I think I did it last time using nested if statements, but that doesn't seem to work now. Has something changed in FM version 7 or 8, regarding dates?

##### Share on other sites

btw, the are "greater than or equal to" symbols, they changed when posted.

##### Share on other sites

I figured it out:

If (field > date(month,day,year); if(field

##### Share on other sites

It seems to me you're making this more complicated than it needs to be.

First, the Case() function is better suited for multiple tests than nested If's.

Next, you only need to check a single boundary. Also, it is not clear why the year - or the day - should play a role in what seems to be a calculation of quarter; a quarter is given by the month alone:

Case (

Month ( Datefield )

Month ( Datefield )

Month ( Datefield )

"Q4" )

Or simply:

"Q" & Div ( Month ( Datefield ) - 1 ; 3 ) + 1

##### Share on other sites

Comment,

Thanks for your advice, it works just like I wanted! The people here are great; I wish I'd discovered this site earlier, that's for sure. And thanks to everyone who responded-

##### Share on other sites

...and, couldn't the same philosophy be utilized for business quarters (1st Quarter=1, 2nd Quarter=2, etc.)? However, then one would need years...if looking for comparisons...

Leoff

##### Share on other sites
This thread is quite old. Please start a new thread rather than reviving this one.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×
×
• Create New...