How Do I Calculate the Day/Month/Year Portion of a Given Date Value? (Magic xpa 3.x)
When you need to work with a date in a program, you usually want to deal with one “piece” of the date. For instance, you might want to summarize all the records for one month, or for one year.
There are three functions in Magic xpa that are used to break apart a date:
-
Day(date) returns the day of the month
-
Month(date) returns the numerical month
-
Year(date) returns the numerical year
Where date is any date variable (or a hard-coded date, such as '05/06/2008'DATE, or an expression that evaluates to a date).
Hint: If you need to do computations based on the month, it is better to use a different function, Month(). This returns the month number rather than the name, which is easier to use in programs.
Hint: If you want to print the month or day of week, there are two other functions, CDOW() and CMonth(), which return the text version. See How Do I Retrieve the Name of the Day of the Week of a Given Day?.
The Online and Rich Client Samples projects (program DT14 and RDT14)