Tips   >   Functions   >   Date Functions

Date Functions

This section provided explanations and demos of the various date function as applicable.

To view all of the date functions:

  1. Press F9 to open the Catalog.
  2. Click the Functions tab.
  3. Click Date and Time in column one. All of the date and time functions are displayed in column two.

    If you hover or one of the date functions a tooltip tip appears providing you with the syntax and a short description of the function.
Tip

You can drag and drop any of the functions into your code. Omnis Studio conveniently copies the function and parameter names into your code.

Many of the date functions require Date Parts contants values, (e.g. kDay, kDayOfWeek, kYear, kSaturday), or Date Codes values. (e.g. y - 1989, N - minutes)

To find the Date Parts and Date Codes:

  1. Press F9 to open the Catalog.
  2. Click the Constants tab.
  3. Click either Date Code or Date Parts in column one. The available constants will be displayed in column two.
Tip

If your are entering code in the code editor, you can drag and drop or double-click on any of the constants in the F9 Catalog. Omnis Studio will copy the constant to your code.

dadd()

Date Add

dadd(kDateCode,Value,Date)

Adds the Value, in kDateConstant units, to the Date.

; Delete 1 day from today.
Calculate NewDate as dadd(kDay,-1,#D)

; Add 2 weeks to today.
Calculate NewDate as dadd(kWeek,2,#D)

; Add 1 year to today.
Calculate NewDate as dadd(kYear,1,#D)

Click the Run Demo button in the StudioTips Browser for a demonstration.

dat()

Date

dat(StringOrNumber,[date format])

Converts a string or number to a date. The date format will be the default #FD format, unless you specific a format in the 2nd parameter. Be sure the date format of the string matches the #FD or include the optional date format parameter.

I find this function useful when importing dates from a text file or spreadsheet.

; Convert date string to a date variable.

Calculate String as '15-SEP-2006'
Calculate DateVar as dat(String,'D-m-y')

Calculate String as '2006-08-31'
Calculate DateVar as dat(String,'y-M-D')

Calculate String as '12/31/2005'
Calculate DateVar as dat(String,'M/D/y')

ddiff()

Date Difference

ddiff(kDateConstant,Date1,Date2)

Calculates the value of Date2 minus Date1 in kDateConstant units.

If you want a positive result the bigger date must be the second date parameter. (Think of it as ascending order).

Calculate Date1 as #D
Calculate Date2 as dadd(kDay,20,#D)

; The number of days between Date1 and Date2.
Calculate DaysDiff as ddiff(kDay,Date1,Date2)

Warning

ddiff() does not calculate decimal values. ddiff() simply truncates the decimal remainder .

If you want to know the difference between two dates by the number of weeks plus days, and you will need to calculate the difference using the kDay constant and then divide the result by 7.

; The number of full weeks between Date1 and Date2.
Calculate WeeksDiff as ddiff(kWeek,Date1,Date2)

; Use the mod() function to calculate the remainder in days.
Calculate RemainderInDays as mod(ddiff(kDay,Date1,Date2),7)

Click the Run Demo button in the StudioTips Browser to see the results of the above sample code.

dim()

Date Increment Months

dim(Date,NumberOfMonths)

Adds the NumberOfMonths to Date. NumberOfMonths can be a positive or negative integer.

; Calculate a new date that is one month after today.
Calculate NewDate as dim(#D,1)

Tip

Use the more flexible dadd() function instead. dadd(kMonth,2,Date)

Click the Run Demo button in the StudioTips Browser for a demonstration.

dname()

Date Name

dname(kDateConstant,Date)

Calculates the month name or day of week name of the date.

Calculate MonthName as dname(kMonth,#D)
Calculate DateName as dname(kDay,#D)

; The jst() function is more flexible.
Calculate DayMonthDateYearString as jst(#D,'D:w, n D, y')

Tip

Use the more flexible jst() function instead. jst(#D,'D:w, n D, y')

Click the Run Demo button in the StudioTips Browser for a demonstration.

dpart()

Date Part

dpart(kDateConstant,Date)

Calculates the kDateConstant value of Date.

Calculate DayOfWeek as dpart(kDayofWeek,#D)
Calculate DayOfYear as dpart(kDayofYear,#D)
Calculate WeekOfMonth as dpart(kWeekofMonth)
Calculate MonthOfYear as dpart(kMonth,#D)

Click the Run Demo button in the StudioTips Browser for a demonstration.

dtcy()

Date Century Year

dtcy(Date)

Calculates the year including century of a date. (e.g. 1985)

Calculate CenturyYearString as dtcy(#D)

Click the Run Demo button in the StudioTips Browser for a demonstration.

dtd()

Date Day

dtd(Date)

Calculates the day of a date (e.g. 6th).

Calculate Day as dtd(#D)

; The jst() function is more flexible.
Calculate DayMonthDateYearString as jst(#D,'D:w, n d, y')

Tip

Use the more flexible jst() function instead. jst(#D,'D:d')

Click the Run Demo button in the StudioTips Browser for a demonstration.

dtm()

Date Month

dtm(Date)

Calculates the month name of a date (e.g. September).

Calculate MonthName as dtm(#D)

; The jst() function is more flexible.
Calculate DayMonthDateYearString as jst(#D,'D:w, n D, y')

Tip

Use the more flexible jst() function instead. jst(#D,'D:n')

Click the Run Demo button in the StudioTips Browser for a demonstration.

dtw()

Date Weekday

dtw(Date)

Calculates the weekday name of a date (e.g. Wednesday).

Calculate DayOfWeekName as dtm(#D)

; The jst() function is more flexible.
Calculate DayMonthDateYearString as jst(#D,'D:w, n D, y')

Tip

Use the more flexible jst() function instead. jst(#D,'D:w')

Click the Run Demo button in the StudioTips Browser for a demonstration.

dty()

Date Year

dty(Date)

Calculates the year excluding the century of a date (e.g. 06).

Calculate YearWithoutCentury as dty(#D)

; The jst() function is more flexible.
Calculate DayMonthDateYearString as jst(#D,'D:w, n D, Y')

Tip

Use the more flexible jst() function instead. jst(#D,'D:Y')

Click the Run Demo button in the StudioTips Browser for a demonstration.

fday()

First Day

fday(kDateConstant,Date)

Calculates the first day of the kDateConstant unit.

Calculate FirstDateOfYear as fday(kYear,#D)
Calculate FirstDateOfMonth as fday(kMonth,#D)
Calculate FirstDateOfWeek as fday(kWeek,#D)

Click the Run Demo button in the StudioTips Browser for a demonstration.

getfye()

Get Fiscal Year End

getfye()

; Get the current (global) Omnis Studio fiscal year end.
Calculate OmnisFiscalYrEnd as getfye()

Warning

The fiscal year related date functions depend on the current Omnis Studio fiscal year end date. If your code makes use of the fiscal year date functions you must be careful to always set the Omnis Studio fiscal year end when you startup your application, or if the user can switch from one company to another company with different fiscal year ends within the same session of Omnis Studio. For setting the Omnis Studio fiscal year see the setfye() function.

Omnis Studio also has a fiscal year end date stored in each library's preference property.

; Each library has a $fiscalyearend property.
Calculate LibraryFiscalYrEnd as $clib.$prefs.$fiscalyearend()

  1. Select any library in the F2 Browser.
  2. Press F6 to open the Property Manager.
  3. Click the Prefs tab, and look for the $fiscalyearend property.
The $fiscalyearend property and getfye() function are independent of each other.

getws()

Get Week Start

getws()

Returns the day of the week which is set as the beginning of the week.

The day of the week is returned as one of the date part constants: kSunday, kMonday, kTuesday, kWednesday, kThursday, kFriday, kSaturday.

Omnis Studio also has a $weekstart property stored in each library's preference property.

; Get the current (global) Omnis Studio week start.
Calculate OmnisWeekStart as getws()

; Each library has a $weekstart property.
Calculate LibraryWeekStart as $clib.$prefs.$weekstart()

  1. Select any library in the F2 Browser.
  2. Press F6 to open the Property Manager.
  3. Click the Prefs tab, and look for the $weekstart property.
The $weekstart property and getws() function are independent of each other.

isoweek()

isoweek(Date)

Returns the ISO 8601 standard week number for the week containing the specified date.

; Get the ISO week for today.
Calculate ISOWeekNum as isoweek(#D)

Click the Run Demo button in the StudioTips Browser for a demonstration.

lday()

Last Day

lday(kDateConstant,Date)

Calculates the last day of the kDateConstant unit.

Calculate LastDateOfYear as lday(kYear,#D)
Calculate LastDateOfMonth as lday(kMonth,#D)
Calculate LastDateOfWeek as lday(kWeek,#D)

Click the Run Demo button in the StudioTips Browser for a demonstration.

nday()

Next Day

nday(kDateConstant,Date)

Calculates the next day occurence of the kDateConstant unit, after the Date.

Constants that can be used: kDay, kSunday, kMonday, kTuesday, kWednesday, kThursday, kFriday, kSaturday

Calculate NextDay as nday(kDay,#D)
Calculate NextSaturday as nday(kSaturday,#D)
Calculate NextWednesday as nday(kWednesday,#D)

Click the Run Demo button in the StudioTips Browser for a demonstration.

pday()

Previous Day

pday(kDateConstant,Date)

Calculates the previous day occurence of the kDateConstant unit, after the Date.

Constants that can be used: kDay, kSunday, kMonday, kTuesday, kWednesday, kThursday, kFriday, kSaturday

Calculate PrevDay as pday(kDay,#D)
Calculate PrevSaturday as pday(kSaturday,#D)
Calculate PrevWednesday as pday(kWednesday,#D)

Click the Run Demo button in the StudioTips Browser for a demonstration.

setfye()

Set Fiscal Year End

setfye('Month Day')

; Set the current (global) Omnis Studio fiscal year end.
Do setfye('JAN 31')

; Check the Omnis Studio fiscal year end.
Calculate OmnisFiscalYrEnd as getfye()

This affects fiscal kDateConstants such as:

kMonthofQuarter, kWeekofQuarter, kDayofQuarter

Warning

The fiscal year related date functions depend on the current Omnis Studio fiscal year end date. If your code makes use of the fiscal year date functions you must be careful to always set the Omnis Studio fiscal year end when you startup your application, or if the user can switch from one company to another company with different fiscal year ends within the same session of Omnis Studio.

Omnis Studio also has a fiscal year end date stored in each library's preference property.

; Each library has a $fiscalyearend property.
Calculate LibraryFiscalYrEnd as $clib.$prefs.$fiscalyearend()

  1. Select any library in the F2 Browser.
  2. Press F6 to open the Property Manager.
  3. Click the Prefs tab, and look for the $fiscalyearend property.

You can use notation to set the library fiscal year end property.

; Set the $fiscalyearend property for the current library.
Calculate LibraryFiscalYrEnd as dat('31-JAN-1900','D-m-Y')
Do $clib.$prefs.$fiscalyearend.$assign(LibraryFiscalYrEnd)

; Check the library fiscal year end property.
Calculate LibraryFiscalYrEnd as $clib.$prefs.$fiscalyearend()

setws()

SET WEEK START

setws(kDayConstant)

Sets the beginning of the week to a particular day, using one of the day of the week datepart constants.

The day of the week is returned as one of the datepart constants: kSunday, kMonday, kTuesday, kWednesday, kThursday, kFriday, kSaturday.

Set Week Start

setws(kDayConstant)

Sets the beginning of the week to a particular day. The datepart constants must be one of the following: kSunday, kMonday, kTuesday, kWednesday, kThursday, kFriday, kSaturday.

; Set the current (global) Omnis Studio week start day.
Do setws(kSunday)

; Check the Omnis Studio week start.
Calculate WeekStart as getws()

Omnis Studio also has a week start stored in each library's preference property.

; Each library has a $weekstart property.
Calculate LibraryWeekStart as $clib.$prefs.$weekstart()

  1. Select any library in the F2 Browser.
  2. Press F6 to open the Property Manager.
  3. Click the Prefs tab, and look for the $weekstart property.

You can use notation to set the library week start property.

; Set the $weekstart property for the current library.
Do $clib.$prefs.$weekstart.$assign(kSunday)

; Check the library fiscal year end property.
Calculate LibraryWeekStart as $clib.$prefs.$weekstart()

tim()

tim(StringOrNumber,[Format])

Convert a string or number to a time format.

The time format will default to the current #FT format, unless you specific a format in the 2nd parameter.

It is pretty hard to mess up the tim() function. You can send it '17:30' or '5:30 PM' and it works for any #FT setting.

; Check the Omnis Studio week start.
Calculate ShortTimeVar as tim('5:30 PM')
Calculate ShortTimeVar as tim('17:30')