datetime_add()datetime_add()

计算新的 datetime,方法是将指定 datapart 与指定数量相乘,然后加上指定 datetimeCalculates a new datetime from a specified datepart multiplied by a specified amount, added to a specified datetime.

语法Syntax

datetime_add(period,amount,datetime) datetime_add(period,amount,datetime)

参数Arguments

period 的可能值:Possible values of period:

  • YearYear
  • QuarterQuarter
  • MonthMonth
  • WeekWeek
  • 日期Day
  • HourHour
  • MinuteMinute
  • SecondSecond
  • MillisecondMillisecond
  • MicrosecondMicrosecond
  • NanosecondNanosecond

返回Returns

添加特定时间/日期间隔之后的日期。A date after a certain time/date interval has been added.

示例Examples

print  year = datetime_add('year',1,make_datetime(2017,1,1)),
quarter = datetime_add('quarter',1,make_datetime(2017,1,1)),
month = datetime_add('month',1,make_datetime(2017,1,1)),
week = datetime_add('week',1,make_datetime(2017,1,1)),
day = datetime_add('day',1,make_datetime(2017,1,1)),
hour = datetime_add('hour',1,make_datetime(2017,1,1)),
minute = datetime_add('minute',1,make_datetime(2017,1,1)),
second = datetime_add('second',1,make_datetime(2017,1,1))

yearyear quarterquarter 月份month weekweek dayday hourhour minuteminute 第 2 个second
2018-01-01 00:00:00.00000002018-01-01 00:00:00.0000000 2017-04-01 00:00:00.00000002017-04-01 00:00:00.0000000 2017-02-01 00:00:00.00000002017-02-01 00:00:00.0000000 2017-01-08 00:00:00.00000002017-01-08 00:00:00.0000000 2017-01-02 00:00:00.00000002017-01-02 00:00:00.0000000 2017-01-01 01:00:00.00000002017-01-01 01:00:00.0000000 2017-01-01 00:01:00.00000002017-01-01 00:01:00.0000000 2017-01-01 00:00:01.00000002017-01-01 00:00:01.0000000