Dr.Hamed Posted August 28, 2011 Posted August 28, 2011 I have a field for people names and a field for their birthdays. I like to have a field that calculates the remaining days for their birthdays so that I can sort the upcoming birthdays in an ascending or descending order. Thanks.
LaRetta Posted August 28, 2011 Posted August 28, 2011 I'm a bit rusty but try this: Let ( [ d = Get ( CurrentDate ) ; thisDOB = Date ( Month ( DOB ) ; Day ( DOB ) ; Year ( d ) ) ; nextDOB = Date ( Month ( DOB ) ; Day ( DOB ) ; Year ( d ) + 1 ) ; days = Case ( thisDOB < d ; nextDOB ; thisDOB ) - d ] ; If ( thisDOB = d ; "Happy Birthday!!!" ; days & " day" & Case ( days > 1 ; "s" ) & " until your birthday." ) ) Result of this calculation is text and check 'do not store calculation results...' in the Storage Options so it updates. UPDATED: improved calc per suggestion below 1
LaRetta Posted August 28, 2011 Posted August 28, 2011 Yikes, you changed the requirements! If you only want the number of days then change the calc to result of number: Let ( [ d = Get ( CurrentDate ) ; thisDOB = Date ( Month ( DOB ) ; Day ( DOB ) ; Year ( d ) ) ; nextDOB = Date ( Month ( DOB ) ; Day ( DOB ) ; Year ( d ) + 1 ) ] ; Case ( thisDOB < d ; nextDOB ; thisDOB ) - d ) UPDATED: improved calc per suggestion below
comment Posted August 28, 2011 Posted August 28, 2011 A small nitpick: thisDOB - d < 0 can be written as: thisDOB < d 1
LaRetta Posted August 28, 2011 Posted August 28, 2011 I’m not sure I agree and the calcs show different results. Can we walk through the logic? result of ThisDOB - d might be -97. If so: -97 < 0 is Boolean test which would return true. -97 is number result which would return true but so would 369. Take date of 8/31/xxxx. I suppose I could have used Sign() or reversed the Case() but ... :^)
LaRetta Posted August 28, 2011 Posted August 28, 2011 Oooops. I misread < for -. I now see what you mean. Of course! DOH! I AM rusty! UPDATE: I am going to correct both calcs in case someone see the calc and grabs it without reading the rest of the thread.
comment Posted August 28, 2011 Posted August 28, 2011 The logic is that a - b returns a negative result if (and only if) b is larger than a. Another way to look at it is in terms of an equation: you can add the same value to both sides. Start with: a - b < 0 and add b to both sides.
Dr.Hamed Posted September 5, 2011 Author Posted September 5, 2011 Thanks. The calculation works fine; however, it does not update the results with current date changes.
comment Posted September 5, 2011 Posted September 5, 2011 check 'do not store calculation results...' in the Storage Options so it updates.
Recommended Posts
This topic is 5168 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now