Identify Rules that Predict Patient’s Heart Disease - An Application of Decis...
Fun with Date Functions, Formulas, and Birthdays
1. How To: Have Fun
with Birthdates!
Beth Breisnes
@bethbrains
Consultant, Bigger Boat Consulting
…and date formulas!
2. Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements
that involve risks, uncertainties, and assumptions. If any such
uncertainties materialize or if any of the assumptions proves
incorrect, the results of salesforce.com, inc. could differ
materially from the results expressed or implied by the
forward-looking statements we make. All statements other
than statements of historical fact could be deemed forward-
looking, including any projections of product or service
availability, subscriber growth, earnings, revenues, or other
financial items and any statements regarding strategies or
plans of management for future operations, statements of
belief, any statements concerning new, planned, or upgraded
services or technology developments and customer contracts
or use of our services.
The risks and uncertainties referred to above include – but
are not limited to – risks associated with developing and
delivering new functionality for our service, new products and
services, our new business model, our past operating losses,
possible fluctuations in our operating results and rate of
growth, interruptions or delays in our Web hosting, breach of
our security measures, the outcome of any litigation, risks
associated with completed and any possible mergers and
acquisitions, the immature market in which we operate, our
relatively limited operating history, our ability to expand,
retain, and motivate our employees and manage our growth,
new releases of our service and successful customer
deployment, our limited history reselling non-salesforce.com
products, and utilization and selling to larger enterprise
customers. Further information on potential factors that could
affect the financial results of salesforce.com, inc. is included
in our annual report on Form 10-K for the most recent fiscal
year and in our quarterly report on Form 10-Q for the most
recent fiscal quarter. These documents and others containing
important disclosures are available on the SEC Filings
section of the Investor Information section of our Web site.
Any unreleased services or features referenced in this or
other presentations, press releases or public statements are
not currently available and may not be delivered on time or at
all. Customers who purchase our services should make the
purchase decisions based upon features that are currently
available. Salesforce.com, inc. assumes no obligation and
does not intend to update these forward-looking statements.
Safe Harbor
5. • Date functions
• Helpful math functions
• Calculate birthday this year
• Calculate next birthday
• Birthday monitoring
• Calculate age in years
• Calculate age in months
• Find last day of the month of a given date
• Calculate membership expiry date
Agenda
7. • Function Argument Return Data Type
• DAY(Date__c) Date__c Number
• MONTH(Date__c) Date__c Number
• YEAR(Date__c) Date__c Number
• TODAY() Date
• NOW() DateTime
• DATE(yyyy,mm,dd) 3 Numbers Date
• DATEVALUE() DateTime Date
Date Functions
8. • Function Argument Return Data Type
• MOD() 2 Numbers Number
• Returns the remainder after you divide by a specific divisor
• MOD(3,3) = 0
• MOD(4,3) = 1
• FLOOR() Number Number
• Rounds a number down to the nearest whole number
Math Functions
10. IF ( MONTH (Birthdate) = 2 && DAY (Birthdate) = 29,
IF ( DATE ( YEAR ( TODAY() ), 1, 1 ) + 59 > TODAY(),
DATE ( YEAR ( TODAY() ), 1, 1) + 59,
DATE ( YEAR ( TODAY() )+1, 1, 1) + 59),
IF (DATE (YEAR(TODAY()),MONTH(Birthdate),DAY(Birthdate)) > TODAY(),
DATE(YEAR(TODAY()),MONTH(Birthdate),DAY(Birthdate)),
DATE(YEAR(TODAY())+1,MONTH(Birthdate),DAY(Birthdate))
)
)
Calculate Next Birthday
11. FLOOR( ( TODAY() - Birthdate ) / 365.2425 )
Calculate Age based on Birthdate
Find number of days
Divide by 1 year, including Leap Year fraction
Round down
12. YEAR(TODAY()) - YEAR(DOB__c) –
IF(
OR (MONTH(TODAY()) < MONTH(DOB__c),
AND( MONTH(TODAY()) == MONTH(DOB__c),
DAY(TODAY()) < DAY(DOB__c)
)
),
1,
0
)
A Better Way to Calculate Age based on Birthdate
13. ((YEAR( TODAY())*12) + MONTH(TODAY()))-
((YEAR(Birthdate)*12) + MONTH(Birthdate))-
IF(DAY(Birthdate)>DAY(TODAY()),
1,
0
)
Calculate Age in Completed Months
14. IF( MONTH( date ) = 12,
DATE( YEAR( date ), 12, 31 ),
DATE( YEAR( date ), MONTH ( date ) + 1, 1 ) - 1 )
If it’s December – this year, Dec 31.
Otherwise – this year, find next month’s 1st, come back 1 day.
Find the Last Day of the Month of a given Date
15. IF ( MONTH (Join_Date__c) = 2 && DAY (Join_Date__c) = 29,
Join_Date__c + 365,
DATE( YEAR(Join_Date__c) + 1, MONTH(Join_Date__c), DAY (Join_Date__c))
-1
)
Calculate Membership Expiry Date (add 1year-1day to a date)
Modified from Salesforce Saint
Membership dates
Expiry dates
Program dates
Anniversaries
Instructor Notes:
Warning
Who can find the 2 problems with doing it this way?
If they were born on a leap day,
Are we still before feb 29/mar 1?
If so, Feb 29/Mar 1 of this year is their next birthday.If not, Feb 29/Mar 1 of NEXT year is their next birthday.
If they weren’t born on a leap day, are we still before their next birthday?
If so, their birthday’s month and day this year is their next birthday.If not, their birthday’s month and day NEXT year is their next birthday.
Quick mental math – this year minus birth year, minus….
Either a 1 if their birthday hasn’t passed, or a 0 if it has passed.
Check if it’s passed – if either today’s month is less than their birthday’s month
OR it IS their birthday month but the day hasn’t passed yet.
Same logic!
Today’s year x 12 months + today’s month MINUSBirth year x 12 months + birth month MINUS
Check if the birthdate day has already passed.
If it has, less one.
If it hasn’t, less zero.
Doesn’t matter if it’s a 30/31/28/29 day month.
If you joined on a leap day,
Forward 365.
Otherwise, same date next year, back up a calendar day. – allows for leap years, same logic as previous one – doesn’t matter if it’s a leap year or not.