# setdateyearmonth - 指令碼與圖表函數

此函數將 timestamp、month 和 year 作為輸入，並以輸入中指定的 year 和 month 更新 timestamp 。.

語法：

SetDateYearMonth (timestamp, year, month)

**傳回資料類型：**雙值

引數：

SetDateYearMonth 引數

| 引數 | 描述 |
| --- | --- |
| timestamp | 要轉換的時間戳記或解析為時間戳記的運算式的日期，例如 '2012-10-12'。 |
| year | 四位數的年度。 |
| month | 1 位數或 2 位數的月份。 |

範例與結果：

這些範例使用日期格式 DD/MM/YYYY。日期格式在您的載入指令碼頂部的 SET DateFormat 陳述式中指定。變更範例中的格式以符合您的要求。

範例 1:

`setdateyearmonth ('29/10/2005', 2013, 3)`

傳回 '29/03/2013

範例 2:

`setdateyearmonth ('29/10/2005 04:26:14',   2013, 3)`

傳回 '29/03/2013 04:26:14'

若要查看圖表中時間戳記的時間部分，您必須將數字格式設定為日期，並為該顯示時間值的格式設定選擇一個值。

範例 3:

新增範例指令碼到您的文件中並加以執行。然後至少將結果資料行中所列的欄位新增至您文件中的工作表，以查看結果。

`SetYearMonth:` `Load *,` `SetDateYearMonth(testdates, 2013,3) as NewYearMonth` `Inline [` `testdates` `1/11/2012` `10/12/2012` `2/1/2013` `19/5/2013` `15/9/2013` `11/12/2013` `14/5/2014` `13/6/2014` `7/7/2014` `4/8/2014` `];`

產生的表格包含原始日期及資料行，其中年已設為 2013。

範例 3 結果

| testdates | NewYearMonth |
| --- | --- |
| 1/11/2012 | 1/3/2013 |
| 10/12/2012 | 10/3/2013 |
| 2/1/2012 | 2/3/2013 |
| 19/5/2013 | 19/3/2013 |
| 15/9/2013 | 15/3/2013 |
| 11/12/2013 | 11/3/2013 |
| 14/5/2014 | 14/3/2013 |
| 13/6/2014 | 13/3/2013 |
| 7/7/2014 | 7/3/2013 |
| 4/8/2014 | 4/3/2013 |