Tips   >   Functions   >   Date Functions
This section provided explanations and demos of the various date function as applicable.
To view all of the date functions:
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 kDay, kDayOfWeek, kYear, kSaturday), or values. (e.g. y - 1989, N - minutes)
contants values, (e.g.To find the
and :If your are entering code in the code editor, you can drag and drop or double-click on any of the constants in the
. Omnis Studio will copy the constant to your code.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)
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')
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)
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)
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)
Use the more flexible dadd() function instead. dadd(kMonth,2,Date)
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')
Use the more flexible jst() function instead. jst(#D,'D:w, n D, y')
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)
Date Century Year
dtcy(Date)
Calculates the year including century of a date. (e.g. 1985)
Calculate CenturyYearString as dtcy(#D)
Click the button in the for a demonstration.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')
Use the more flexible jst() function instead. jst(#D,'D:d')
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')
Use the more flexible jst() function instead. jst(#D,'D:n')
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')
Use the more flexible jst() function instead. jst(#D,'D:w')
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')
Use the more flexible jst() function instead. jst(#D,'D:Y')
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)
Get Fiscal Year End
getfye()
; Get the current (global) Omnis Studio fiscal year end.
Calculate OmnisFiscalYrEnd as getfye()
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()
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()
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)
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)
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)
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)
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
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()
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()
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()
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(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')