I will be discussing how to manipulate time and date in Sage X3.
To get the current date in a Date variable , use the date function $ .
In the same way, to have the current date and time in a Datetime variable , use the datetime function $ (only from U9).
The canonical form to represent date and time with a string is:
YYYY-MM-DDThh: mm: ssZ #attention to the "extra" letters T and Z
Generally, date and time have “YYYY-MM-DDThh: mm: ss” format
num $ (date $) #To get today's date string num $ (time $) #To get the current time as a string num $ (datetime $) #To get today's date and time as a canonical string gdat $ (DAY, MONTH, YEAR) #To get a date, day, month and year data gdatetime $ (str) #To get a Datetime variable from a canonical string year (date) #To get the year of a date month (data) #To get the month number of a date month $ (date) #To get the month name of a date in the current language day (data) #To get the day number of the month (1-31) day $ (date) #To get the name of the day of the week dayn (data) #To get the day of the week number (1 = Monday, 7 = Sunday) week (date) #To get the week number (1-53) nday (data) #To get the number of days passed since January 1, 1600 nday $ (NUM) #To get a later date of NUM days from January 1, 1600 eomonth (data) #To get the last day of a given month
You can also perform simple operations:
Local Date DATA DATE = [1/2/2015] +5 #DATA will contain [06/02/2015] DATA = [1/2/2015] -1 #DATA will contain [31/01/2015]
Local date LASTDATE LASTDATE = eomonth ([1/2/2015]) Infbox num $ (LASTDATE) # will display the date [28/02/2015]
To obtain a date as a string with the desired format:
format $ ( "D: YYYYMMDD [_] hhmmss", $ date)
December 31, 2018 at 12.30 and 56 seconds will correspond to “20181231_123056”.
Note that square brackets are used to insert a space or other constant elements:
FORMATO = "DD[ ]MM[ ]YY"
To get the date and time as a formatted string, you can also use AFNC.FDH.
With this call, use the formatting contained in the global variable GFMDAT.
Suppose today is January 19, 2018, and GFMDAT contains “DD [/] MM [/] YY”:
func AFNC.FDH (dates $, "121531") # returns "01/19/18 12:15:31" func AFNC.FDH (dates $, "") # returns "19/01/18 17:08:27" func AFNC.FDH (dates $, "15:32") # returns "19/01/18 15:32:00" func AFNC.FDH (dates $, "15") # returns "19/01/18 15:00:00" func AFNC.FDH (dates $, "15:") # returns "19/01/18 15:00:00" func AFNC.FDH (date $, "string-errata") # returns "19/01/18" func AFNC.FDH (dates $ + 1, "x") # returns "01/20/18"
It must be remembered that there are several global variables containing formatting strings,
all preset according to the various predefined parameters.
They are useful for maintaining a standard that is adapted to different users, sites, etc.
The order day-month-year of these formats depends precisely on the location and user settings.
The variables are these:
GFMDAT = standard date, with 2 characters per day, 2 for the month, 2 for the year
GFMDAT4 = date with the 4-digit year
GFMDAT3 = date with the month expressed in three letters
GFMDAT9 = date with the month written in letters
GFMMOI = month-year
GFMMOI4 = month-year with 4-digit year
GFMJOU = day-month