# setdateyearmonth - 脚本和图表函数

此函数用于输入 timestamp、month 和 year ，并使用在输入中指定的 year 和 month 更新 timestamp 。 .

语法：

SetDateYearMonth (timestamp, year, month)

返回数据类型： 双

参数：

参数

| 参数 | 说明 |
| --- | --- |
| timestamp | 标准的 Qlik Sense 时间戳（通常只是一个日期）。 |
| year | 一个四位数年份。 |
| month | 一位或两位数月份。 |

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/DateAndTimeFunctions/setdateyearmonth.htm)

#### 示例和结果：

以下示例使用日期格式 DD/MM/YYYY。日期格式已经在数据加载脚本顶部的 SET DateFormat 语句中指定。可以根据要求更改示例中的格式。

脚本示例

| 示例 | 结果 |
| --- | --- |
| `setdateyearmonth ('29/10/2005', 2013, 3)` | 返回“29/03/2013” |
| `setdateyearmonth ('29/10/2005 04:26:14',<br>2013, 3)` | 返回“29/03/2013 04:26:14”<br><br>要在可视化中查看时间戳的时间部分，您必须将数字格式设置为日期，并选择用于显示时间值的格式的值。 |

示例：

将示例脚本添加到应用程序并运行。要查看结果，将结果列中列出的字段添加到应用程序中的工作表。

`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 的列。

结果表

| 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 |