Jump to content
Sign in to follow this  
Mr. Bungle

Date Calculation

Recommended Posts

Mr. Bungle

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! grin.gif

Share this post


Link to post
Share on other sites
comment

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

Share this post


Link to post
Share on other sites
Johnny Boy

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 this post


Link to post
Share on other sites
comment

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 this post


Link to post
Share on other sites
Mr. Bungle

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 this post


Link to post
Share on other sites
comment

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 this post


Link to post
Share on other sites
Johnny Boy

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 this post


Link to post
Share on other sites
Mr. Bungle

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 this post


Link to post
Share on other sites
comment

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

Share this post


Link to post
Share on other sites
blevey

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 this post


Link to post
Share on other sites
blevey

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

Share this post


Link to post
Share on other sites
blevey

I figured it out:

 

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

Share this post


Link to post
Share on other sites
comment

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 this post


Link to post
Share on other sites
Mr. Bungle

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 this post


Link to post
Share on other sites
Leoff

...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 this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Sign in to follow this  



×
×
  • Create New...

Important Information

Terms of Use