How Do I Retrieve the Current Date? (Magic xpa 3.x)
Getting the current date in Magic xpa is done using the Date() function. Date() returns the system date, as it exists on the machine Magic xpa is running on.
Note: You might notice two similar functions, UTCDate() and MDate(). The UTCDate() function works the same as the Date() function, but returns the UTC date instead of the system date. The MDate() function does not return the system date, rather, it returns the date as returned in the Magic Date environment setting.
Dates in Magic xpa are stored internally as an integer, which represents the number of days since the year zero. This isn’t something you need to deal with, since all the conversions are done automatically. But it means that in terms of arithmetic, a date is considered just a number. So if you add 5 to a date, you get a date 5 days from the original. You don’t need to worry about issues like “is the date at the end of the month” or “is it a leap year”.
When dates are stored in your data source, the storage is determined by the properties set up in the data source definition. If you are sharing the data with any other tools, such as report writers, it is important that the definition of the date field be something the other tool can handle.
The Date() function is often used in an Init column, as shown here. This will set the field to the current date the first time the user sees the screen, and is also useful for setting timestamps for when a record was created or modified.
To use it, you just type Date(). At runtime, the function will be replaced by the current date.
The Online and Rich Client Samples projects (program DT01 and RDT01)