PowerApps 中的 Day、Month、Year、Hour、Minute、Second 和 Weekday 函数Day, Month, Year, Hour, Minute, Second, and Weekday functions in PowerApps

返回日期/时间值的各个部分。Returns individual components of a Date/Time value.

说明Description

Day 函数可用于返回日期/时间值的日部分,范围是 1 到 31。The Day function returns the day component of a Date/Time value, ranging from 1 to 31.

Month 函数可用于返回日期/时间值的月部分,范围是 1 到 12。The Month function returns the month component of a Date/Time value, ranging from 1 to 12.

Year 函数可用于返回日期/时间值的年部分,从 1900 开始。The Year function returns the year component of a Date/Time value, starting with 1900.

Hour 函数可用于返回日期/时间值的小时部分,范围是 0(凌晨12:00)到 23(午夜 11:00 点)。The Hour function returns the hour component of a Date/Time value, ranging from 0 (12:00 AM) to 23 (11:00 PM).

Minute 函数可用于返回日期/时间值的分钟部分,范围是 0 到 59。The Minute function returns the minute component of a Date/Time value, ranging from 0 to 59.

Second 函数可用于返回日期/时间值的秒部分,范围是 0 到 59。The Second function returns the second component of a Date/Time value, ranging from 0 to 59.

Weekday 函数可用于返回日期/时间值的星期几。The Weekday function returns the weekday of a Date/Time value. 默认情况下,结果范围是 1(星期日)到 7(星期六)。By default, the result ranges from 1 (Sunday) to 7 (Saturday). 可以使用 Microsoft Excel 的 Weekday 函数代码或 StartOfWeek 枚举值来指定其他范围:You can specify a different range with an Microsoft Excel Weekday function code or a StartOfWeek enumeration value:

Excel 代码Excel code StartOfWeek 枚举StartOfWeek enumeration 说明Description
1, 171, 17 StartOfWeek.SundayStartOfWeek.Sunday 数字 1(星期日)到 7(星期六)。Numbers 1 (Sunday) through 7 (Saturday). 默认值。Default.
2, 112, 11 StartOfWeek.MondayStartOfWeek.Monday 数字 1(星期一)到 7(星期日)。Numbers 1 (Monday) through 7 (Sunday).
33 StartOfWeek.MondayZeroStartOfWeek.MondayZero 数字 0(星期一)到 6(星期日)。Numbers 0 (Monday) through 6 (Sunday).
1212 StartOfWeek.TuesdayStartOfWeek.Tuesday 数字 1(星期二)到 7(星期一)。Numbers 1 (Tuesday) through 7 (Monday).
1313 StartOfWeek.WednesdayStartOfWeek.Wednesday 数字 1(星期三)到 7(星期二)。Numbers 1 (Wednesday) through 7 (Tuesday).
1414 StartOfWeek.ThursdayStartOfWeek.Thursday 数字 1(星期四)到 7(星期三)。Numbers 1 (Thursday) through 7 (Wednesday).
1515 StartOfWeek.FridayStartOfWeek.Friday 数字 1(星期五)到 7(星期四)。Numbers 1 (Friday) through 7 (Thursday).
1616 StartOfWeek.SaturdayStartOfWeek.Saturday 数字 1(星期六)到 7(星期五)。Numbers 1 (Saturday) through 7 (Friday).

上述所有函数都返回一个数字。All functions return a number.

有关详细信息,请参阅处理日期和时间See working with dates and times for more information.

语法Syntax

Day( DateTime )Day( DateTime )
Month( DateTime )Month( DateTime )
Year( DateTime )Year( DateTime )
Hour( DateTime )Hour( DateTime )
Minute( DateTime )Minute( DateTime )
Second( DateTime )Second( DateTime )

  • DateTime - 必需。DateTime - Required. 要进行运算的日期/时间值。Date/Time value to operate on.

Weekday( DateTime [, WeekdayFirst ] )Weekday( DateTime [, WeekdayFirst ] )

  • DateTime - 必需。DateTime - Required. 要进行运算的日期/时间值。Date/Time value to operate on.
  • WeekdayFirst - 可选。WeekdayFirst - Optional. Excel 代码指定一周从哪一天开始。Excel code specifying which day starts the week. 如果未提供,则使用 1(星期日是第一天)。If not supplied, 1 (Sunday first) is used.

示例Examples

对于下面的示例,当前时间是 2015 年 4 月 9 日星期四下午 3:59:37For the following example, the current time is 3:59:37 PM on Thursday, April 9, 2015.

公式Formula 说明Description 结果Result
Year( Now() )Year( Now() ) 返回当前时间和日期的年部分。Returns the year component of the current time and date. 20152015
Month( Now() )Month( Now() ) 返回当前时间和日期的月部分。Returns the month component of the current time and date. 44
Day( Now() )Day( Now() ) 返回当前时间和日期的日部分。Returns the day component of the current time and date. 99
Hour( Now() )Hour( Now() ) 返回当前时间和日期的小时部分。Returns the hour component of the current time and date. 1515
Minute( Now() )Minute( Now() ) 返回当前时间和日期的分钟部分。Returns the minute component of the current time and date. 5959
Second( Now() )Second( Now() ) 返回当前时间和日期的秒部分。Returns the minute component of the current time and date. 3737
Weekday( Now() )Weekday( Now() ) 返回当前时间和日期的星期几部分,使用默认设置(星期日作为一周的第一天)。Returns the weekday component of the current time and date, using the default start of the week as Sunday. 55
Weekday( Now(), 14 )Weekday( Now(), 14 ) 返回当前时间和日期的星期几部分(使用 Excel 代码指定的星期四作为一周的第一天)。Returns the weekday component of the current time and date, using an Excel code to specify the start of the week as Thursday. 11
Weekday( Now(), StartOfWeek.Wednesday )Weekday( Now(), StartOfWeek.Wednesday ) 返回当前时间和日期的星期几部分(使用 StartOfWeek 枚举指定的星期三作为一周的第一天)。Returns the weekday component of the current time and date, using a StartOfWeek enumeration to specify the start of the week as Wednesday. 22