monthname - script and chart function
This function returns a display value showing the month (formatted according to the MonthNames script variable) and year with an underlying numeric value corresponding to a timestamp of the first millisecond of the first day of the month.
Syntax:
MonthName(date[, period_no])
Return data type: dual
Arguments:
Argument | Description |
---|---|
date | The date to evaluate. |
period_no | period_no is an integer, which, if 0 or omitted, indicates the month that contains date. Negative values in period_no indicate preceding months and positive values indicate succeeding months. |
Examples and results:
These examples use the date format DD/MM/YYYY. The date format is specified in the SET DateFormat statement at the top of your load script. Change the format in the examples to suit your requirements.
Example 1:
monthname('19/10/2013')
Returns Oct
2013.
Because in this and the other examples, the SET Monthnames statement is set to Jan;Feb;Mar, and so on.
Example 2:
monthname('19/10/2013', -1)
Returns Sep 2013.
Example 3:
Add the example script to your document and run it. Then add, at least, the fields listed in the results column to a sheet in your document to see the result.
In this example, for each invoice date in the table, the month name is created from the month name shifted four months from base_date, and from the year.
TempTable:
LOAD RecNo() as InvID, * Inline [
InvDate
28/03/2012
10/12/2012
5/2/2013
31/3/2013
19/5/2013
15/9/2013
11/12/2013
2/3/2014
14/5/2014
13/6/2014
7/7/2014
4/8/2014
];
InvoiceData:
LOAD *,
MonthName(InvDate, 4) AS MthName
Resident TempTable;
Drop table TempTable;
The resulting table contains the original dates and a column with the return value of the monthname() function.
InvDate | MthName |
---|---|
28/03/2012 | Jul 2012 |
10/12/2012 | Apr 2013 |
5/2/2013 | Jun 2013 |
31/3/2013 | Jul 2013 |
19/5/2013 | Sep 2013 |
15/9/2013 | Jan 2014 |
11/12/2013 | Apr 2014 |
2/3/2014 | Jul 2014 |
14/5/2014 | Sep 2014 |
13/6/2014 | Oct 2014 |
7/7/2014 | Nov 2014 |
4/8/2014 | Dec 2014 |