Date Functions

The Date Functions category contains six subcategories:

The General subcategory contains the following functions:

Today

Function

Today

Location in PracticeScript

Functions->Date Functions->General

Purpose

Retrieves today's date.

Format

Today()

Evaluates to

The number of days between 01-01-2000 and today's date.

Example

Today() - Patient.LastIn

Calculates the number of days since the patients last visit.

Yesterday

Function

Yesterday

Location in PracticeScript

Functions->Date Functions->General

Purpose

Retrieves yesterday's date.

Format

Yesterday()

Evaluates to

The number of days between 01-01-1900 and yesterday's date. It is functionally equivalent to Today() - 1.

Example

Patient.LastIn = Yesterday()
Evaluates to TRUE if the patient was last in yesterday, FALSE otherwise.

Tomorrow

Function

Tomorrow

Location in PracticeScript

Functions->Date Functions->General

Purpose

Retrieves tomorrow's date.

Format

Tomorrow()

Evaluates to

The number of days between 01-01-2000 and tomorrow's date. It is functionally equivalent to Today() + 1.

Example

NextApptDate(Patient.PersonID) = Tomorrow()
Evaluates to TRUE if the patient has an appointment scheduled for tomorrow, FALSE otherwise.

 The Week related subcategory contains the following functions:

FirstOfWeek

Function

FirstOfWeek

Location in PracticeScript

Functions->Date Functions->Week related

Purpose

Retrieves the date of the previous Sunday of the specified week.

Format

FirstOfWeek(OptionalDate)
OptionalDate
, if specified, is the date on which to base the "first of week" calculation.

If OptionalDate is NOT specified, the value Today() is assumed.

Evaluates to

The number of days between 01-01-1900 and the date of Sunday that is in the same week as the specified date.

Example

FirstOfWeek()
Returns Sunday's date of the current week.

FirstOfWeek()+1
Returns Monday's date of the current week.

FirstOfWeek(LastWeek())
Returns the date of two Sunday's ago (the first of the week that includes LastWeek()).

EndOfWeek

Function

EndOfWeek

Location in PracticeScript

Functions->Date Functions->Week related

Purpose

Retrieves the date of the coming Saturday of the specified week.

Format

EndOfWeek(OptionalDate) OptionalDate, if specified, is the date to use to base the "end of week" calculation on.

If OptionalDate is NOT specified, the value Today() is assumed.

Evaluates to

The number of days between 01-01-1900 and the date of the Saturday that is in the same week as the specified date.

Example

EndOfWeek() Returns Saturday's date of the current week EndOfWeek()-1 Returns Friday's date of the current week.

EndOfWeek(LastWeek())Returns the date of last Saturday (the end of the week that includes LastWeek()).

LastWeek

Function

LastWeek

Location in PracticeScript

Functions->Date Functions->Week related

Purpose

Retrieves the date 7 days prior to the specified date.

Format

LastWeek(OptionalDate)
OptionalDate
, if specified, is the date on which to base the "last week" calculation.

If OptionalDate is NOT specified, the value Today() is assumed.

Evaluates to

The number of days between 01-01-1900 and 7 days prior to the specified date. It is functionally equivalent to OptionalDate - 7.

Example

LastWeek()
Returns the date 7 days ago. It is the same as Today()-7.

NextWeek

Function

NextWeek

Location in PracticeScript

Functions->Date Functions->Week related

Purpose

Retrieves the date 7 days after the specified date.

Format

NextWeek(OptionalDate)
OptionalDate
, if specified, is the date on which to base the "next week" calculation.

If OptionalDate is NOT specified, the value Today() is assumed.

Evaluates to

The number of days between 01-01-2000 and 7 after the specified date. It is functionally equivalent to OptionalDate + 7.

Example

NextWeek()
Returns the date 7 days from today. It is the same as Today()+7. EndOfWeek(NextWeek())
Returns the date of two Saturdays from today (The end of the week that is 7 days from today).

The Day related subcategory contains the following functions:

DayOfWeek

Function

DayOfWeek

Location in PracticeScript

Functions->Date functions->Day related

Purpose

Determines the day of the week for a given date.

Format

DayOfWeek(OptionalDate)
OptionalDate
, if specified, is the date to use for the calculation. If OptionalDate is NOT specified, the value Today() is assumed.

Evaluates to

A number representing the day of the week. Values are 0 for Sunday, 1 for Monday, 2 for Tuesday, etc. through 6 for Saturday.

Example

DayOfWeek() Returns 3 if today is a Wednesday. Returns 5 if today is a Friday.

DayOfWeek(FirstOfMonth()) Returns the day of the week of the first day of this month.

DayOfWeek(EndOfWeek()) ALWAYS returns 6 because EndOfWeek() always evaluates to a Saturday.

DayOfWeekStr

Function

DayOfWeekStr

Location in PracticeScript

Functions->Date functions->Day related

Purpose

Converts the day of week number to a readable character string.

Format

DayOfWeekStr(DayNumber)
DayNumber
is a number between 0 and 6, where 0 = Sunday, 1 = Monday, and 6 = Saturday

Evaluates to

A character string, such as "Sunday" or "Thursday"

Example

DayOfWeekStr(DayOfWeek())
Returns the character string "Wednesday" if today's date is a Wednesday.

DayOfWeekStr(2)
Returns the character string "Tuesday". DayOfWeekStr(DayOfWeek(NextApptDate(Patient.PersonID))) Returns the character string of the day of the week of the patient's next appointment.

Day

Function

Day

Location in PracticeScript

Functions->Date functions->Day related

Purpose

Extracts the "Day of the Month" portion from a date.

Format

Day(OptionalDate)
OptionalDate
, if specified, is the date to calculate the day of the month for. If not specified, Today() is used.

Evaluates to

A number between 1 and 31, representing the "DD" portion of a date if specified in MM-DD-YYYY format.

Example

Day()
Returns 25 if today's date were March 25, 1998

Day (Date("12/27/1997"))
Returns 27

The Month related subcategory contains the following functions:

FirstOfMonth

Function

FirstOfMonth

Location in PracticeScript

Functions->Date functions->Month related

Purpose

Calculates the date that represents the 1st day of the month.

Format

FirstOfMonth(OptionalDate)
OptionalDate
, if specified, is the date that is in the month for which the 1st of the month is to be calculated. If no date is specified, Today() is assumed and the 1st day of the current month is returned.

Evaluates to

The number of days between 01-01-2000 and the 1st day of the month for the specified date.

Example

FirstOfMonth()
Returns the date that is the first of the current month.

FirstOfMonth(Date("12/27/1997"))
Returns the number that represents the date December 1, 1997

EndOfMonth

Function

EndOfMonth

Location in PracticeScript

Functions->Date functions->Month related

Purpose

Calculates the date that represents the last day in a month.

Format

EndOfMonth(OptionalDate)
OptionalDate
, if specified, is the date that is in the month that the last of the month is to be calculated for. If no date is specified, Today() is assumed and the last day of the current month is returned.

Evaluates to

The number of days between 01-01-1900 and the last day of the month for the specified date

Example

EndOfMonth()
Returns the date that is the last of the current month.

EndOfMonth(Date("12/27/1997"))
Returns the number that represents the date December 31, 1997

LastMonth

Function

LastMonth

Location in PracticeScript

Functions->Date functions->Month related

Purpose

Calculates the date that represents the same day of the previous month.

Format

LastMonth(OptionalDate)
OptionalDate
, if specified, is the date to use as the basis of the calculation. If no date is specified, Today() is assumed and date for the same day last month is returned.

Evaluates to

The number of days between 01-01-1900 and the date that is the same day of the month, but one month previous to the specified date.

NOTE
: If the specified date is the 29th, 30th, or 31st of the month, and the previous month does not have a 29th, 30th, or 31st, then the last day of the previous month is returned.

Example

LastMonth()
Returns the date for the previous month that has the same day of the month as today.

LastMonth(Date("12/27/1997"))
Returns the number that represents November 27, 1997.

LastMonth(Date("3/31/1997"))
Returns the number that represents February 28, 1997.

NextMonth

Function

NextMonth

Location in PracticeScript

Functions->Date functions->Month related

Purpose

Calculates the date that represents the same day of the following month.

Format

NextMonth(OptionalDate)
OptionalDate
, if specified, is the date to use as the basis of the calculation. If no date is specified, Today() is assumed, and the date for the same day next month is returned.

Evaluates to

The number of days between 01-01-2000 and the date that is the same day of the month, but one month after the specified date.

NOTE
: If the specified date is the 29th, 30th, or 31st of the month, and the following month does not have a 29th, 30th, or 31st, then the last day of the following month is returned.

Example

NextMonth()
Returns the date for the following month that has the same day of the month as today.

NextMonth(Date("12/27/1997"))
Returns the number that represents January 27, 1998.

NextMonth(Date("3/31/1997"))
Returns the number that represents April 30, 1997 (April does not have 31 days).

Month

Function

Month

Location in PracticeScript

Functions->Date functions->Month related

Purpose

Extracts the "Month number" portion from a date.

Format

Month(OptionalDate)
OptionalDate
, if specified, is the date to calculate the month number for. If not specified, Today() is used.

Evaluates to

A number between 1 and 12, representing the "MM" portion of a date if specified in MM-DD-YYYY.

Example

Month() Returns 3 if today's date were March 25, 1998 Month(Date("12/27/1997")) Returns 12.

MonthStr

Function

MonthStr

Location in PracticeScript

Functions->Date functions->Month related

Purpose

Converts the month number into a readable month.

Format

MonthStr(MonthNumber)
MonthNumber
is a number between 0 and 12 where 1 = January,

and 7 = July.

Evaluates to

A character string, such as "January" or "July."

Example

MonthStr(Month(Person.Birthdate))

Returns the character string of the month of the patient's birthdate.

IncMonth

Function

IncMonth

Location in PracticeScript

Functions->Date functions->Month related

Purpose

To add (increment) or subtract a given number of months from a base date to calculate a date with the same day of the month.

Format

IncMonth(Date, OptionalChangeMonths)
Date
is the base date to use for the calculation. It is a required parameter.

OptionalChangeMonths, if specified, is the number of months to add (or subtract) to the Date parameter. If OptionalChangeMonths is a positive number, it is added. If OptionalChangeMonths is a negative number, it is subtracted. If not specified, 1 is assumed.

Evaluates to

The number of days between 01-01-2000 and the date that is the same day of the month, but OptionalChangeMonths before or after the specified date.

NOTE
: If the specified date is the 29th, 30th, or 31st of the month, and the resulting month does not have a 29th, 30th, or 31st, then the last day of the resulting month is returned.

Example

IncMonth(Patient.LastRecall, 6)
Calculates a patient's next recall date, assuming it is 6 months after the last recall date.

IncMonth(Patient.LastRecall, Patient.RecallCycle)
Calculates a patient's next recall date using their actual recall cycle.

IncMonth(Date("12/27/1997"))
Returns the number that represents January 27, 1998.

IncMonth(Date("12/27/1997"), -1)
Returns the number that represents November 27, 1997.

The Year related subcategory contains the following functions:

FirstOfYear

Function

FirstOfYear

Location in PracticeScript

Functions->Date functions->Year related

Purpose

Calculates the date that represents January 1 of the year including the specified date.

Format

FirstOfYear(OptionalDate)
OptionalDate
, if specified, is the date that is in the year for which the 1st of the year is to be calculated. If no date is specified, Today() is assumed and the 1st of the current year is returned.

Evaluates to

The number of days between 01-01-2000 and the 1st day of the year for the specified date.

Example

FirstOfYear()
Returns the date that is January 1 of the current year.

YearFirstOfYear(Date("12/27/1997"))
Returns the number that represents the date January 1, 1997

EndOfYear

Function

EndOfYear

Location in PracticeScript

Functions->Date functions->Year related

Purpose

Calculate the date that represents the last day in a year.

Format

EndOfYear(OptionalDate)

OptionalDate, if specified, is the date that is in the year that the last of the year is to be calculated for. If no date is specified, Today() is assumed and the last day of the current year is returned.

Evaluates to

The number of days between 01-01-1900 and the last day of the year for the specified date.

Example

EndOfYear()
Returns the date that is December 31 of the current Year.

EndOfYear(Date("12/27/1997")) Returns the number that represents the date December 31, 1997

LastYear

Function

LastYear

Location in PracticeScript

Functions->Date functions->Year related

Purpose

Calculates the date that represents the same date the previous year.

Format

LastYear(OptionalDate)
OptionalDate
, if specified, is the date to use as the basis of the calculation. If no date is specified, Today() is assumed, and the date for the same day last year is returned.

Evaluates to

The number of days between 01-01-1900 and the date that is the same date one year previous to the specified date. It is roughly equivalent to OptionalDate - 365, but correctly handles leap years.

Example

LastYear()
Returns the date for the same date one year ago today. LastYear(Date("12/27/1997"))
Returns the number that represents December 27, 1996.

NextYear

Function

NextYear

Location in PracticeScript

Functions->Date functions->Year related

Purpose

Calculates the date that represents the same date the following year.

Format

NextYear(OptionalDate)
OptionalDate
, if specified, is the date to use as the basis of the calculation. If no date is specified, Today() is assumed, and the date for the same date next year is returned.

Evaluates to

The number of days between 01-01-2000 and the date that is the same day of the year, but one year after the specified date. It is roughly equivalent to OptionalDate + 365, but correctly handles leap years.

Example

NextYear()
Returns the date one year from today.

NextYear(Date("12/27/1997"))
Returns the number that represents December 27, 1998.

Year

Function

Year

Location in PracticeScript

Functions->Date functions->Year related

Purpose

Extracts the "Year number" portion from a date.

Format

Year(OptionalDate)

OptionalDate, if specified, is the date for which to calculate the year number. If not specified, Today() is used.

Evaluates to

A number between 1900 and 2078, representing the "YYYY" portion of a date if specified in MM-DD-YYYY format.

Example

Year()
Returns 1998 if today's date were March 25, 1998.

Year(Date("12/27/1997"))
Returns 1997.

AgeInYears

Function

AgeInYears

Location in PracticeScript

Functions->Date functions->Year related

Purpose

Calculates the difference, in whole years, between a specified date and an optional base date.

Format

AgeInYears(StartDate, OptionalEndDate).

StartDate is the date the age calculation is to begin. It is a required parameter.

OptionalEndDate, if specified, is the date to stop the age calculation on. If not specified, Today() is assumed.

Evaluates to

The number of whole years that have passed between StartDate and OptionalEndDate. Since the most common usage is NOT to specify OptionalEndDate (and use its default value of Today()), the function mainly calculates the number of whole years that has passed since StartDate.

Example

AgeInYears(Person.Birthdate)

Calculates a person's age.

AgeInYears(Date("1/3/1997"), Date("1/1/1998"))
Returns 0, since a whole year has not passed between the start and end dates.

AgeInYears(Date("1/3/1997"), Date("1/3/1998"))
Returns 1, since one whole year has passed between January 3 of 1997 and January 3 of 1998.

The Conversion subcategory contains the following functions:

 

Date

Function

Date

Location in PracticeScript

Functions->Date functions->Conversion

Purpose

Translates a character string representing a human readable date into its numeric equivalent.

Format

Date(CharacterString).
CharacterString
must be in MM-DD-YYYY format (or whichever format is appropriate for the computer's locale). The separator character can be either the - character or the / character. If the year is specified in YY format instead of YYYY format, the current century is assumed.

Evaluates to

The number of days between 01-01-1900 and the date that is represented by the string of characters.

Example

Date("12/27/1997")

Returns 35789, the numeric equivalent to December 27, 1997.
Date("12-27-70")

Returns 62452 (December 27, 2070) since the current century is the 2000's.

DateStr

Function

DateStr

Location in PracticeScript

Functions->Date functions->Conversion

Purpose

Converts a date (number relative to January 1, 1900) to a human readable character string.

Format

DateStr(NumericDate)
NumericDate
is any PracticeScript expression that represents a date.

Evaluates to

A character string formatted as a date.

Example

DateStr(35789)
Returns the string "12-27-1997".

DateStr(Person.Birthdate)
Returns the string that represents the patient's birth date.

SortDateStr

Function

SortDateStr

Location in PracticeScript

Functions->Date functions->Conversion

Purpose

To convert a date (number relative to January 1, 1900) to a human readable character string suitable for sorting. Used as a column in a contact list.

Format

SortDateStr(NumericDate) NumericDate is any PracticeScript expression that represents a date.

Evaluates to

A character string formatted as a date, but places the year first.

NOTE:
The date 01-01-1998 comes after 12-31-1997, but when looked at as a set of characters, "01-01-1998" is sorted before "12-31-1997". By placing the year first, alphanumeric sorting will place the dates in their expected order.

Example

SortDateStr(35789)
Returns the string "1997-12-27".

SortDateStr(Person.Birthdate) Returns the string that represents the patient's birth date.

 

Related Topics

Using Functions

Function Definitions

Practice Answers

Special Functions

Strings Functions

Time Functions

User Defined Functions

Prompt User for Info Functions