天天看點

access日期如何增加年數_ACCESS支援的時間日期函數

ACCESS支援的時間日期函數

參考文章一:

找了半天,終于在微軟的網站找到了,對于做ACCESS資料庫開發人來說還是有點用處的,有時間的話我會把它翻譯成中文。(注:其中大部分對于Access是适用了,有些不行,使用前最好先在Access中試一下)。

DATE Returns the serial number of a particular date

DATEVALUE Converts a date in the form of text to a serial number

DAY Converts a serial number to a day of the month

DAYS360 Calculates the number of days between two dates based on a 360-day year

EDATE Returns the serial number of the date that is the indicated number of months before  or after the start date

EOMONTH Returns the serial number of the last day of the month before  or after a specified number of months

HOUR Converts a serial number to an hour

MINUTE Converts a serial number to a minute

MONTH Converts a serial number to a month

NETWORKDAYS Returns the number of whole workdays between two dates

NOW Returns the serial number of the current date and time

SECOND Converts a serial number to a second

TIME Returns the serial number of a particular time

TIMEVALUE Converts a time in the form of text to a serial number

TODAY Returns the serial number of today's date

WEEKDAY Converts a serial number to a day of the week

WEEKNUM Converts a serial number to a number representing where the week falls numerically with a year

WORKDAY Returns the serial number of the date before  or after a specified number of workdays

YEAR Converts a serial number to a year

YEARFRAC Returns the year fraction representing the number of whole days between start_date and end_date

參考文章二: 設定目前日期或時間。 Date ,Now, Time  計算日期: DateAdd, DateDiff, DatePart  傳回日期: DateSerial, DateValue  傳回時間: TimeSerial, TimeValue  設定日期或時間: Date, Time  計時: Timer  在幫助裡有~ --------------------------- 夠全了! --------------------------- Time 函數        傳回一個指明目前系統時間的 Variant (Date)。 文法  Time 說明 為了設定系統時間,請使用 Time 語句。Time 函數示例 本示例使用 Time 函數傳回系統目前的時間。 Dim MyTime MyTime = Time    ’ 傳回系統目前的時間。 DateAdd 函數        傳回包含一個日期的 Variant (Date),這一日期還加上了一段時間間隔。 文法  DateAdd(interval, number, date) DateAdd 函數文法中有下列命名參數: 部分 描述  interval 必要。字元串表達式,是所要加上去的時間間隔。  number 必要。數值表達式,是要加上的時間間隔的數目。其數值可以為正數(得到未來的日期),也可以為負數(得到過去的日期)。  date 必要。Variant (Date) 或表示日期的文字,這一日期還加上了時間間隔。  設定 interval 參數具有以下設定值: 設定 描述  ==yyyy 年  ==q 季  ==m 月  ==y 一年的日數  ==d 日  ==w 一周的日數  ==ww 周  ==h 時  ==n 分鐘  ==s 秒  說明 可以使用 DateAdd 函數對日期加上或減去指定的時間間隔。例如,可以用 DateAdd 來計算距今天為三十天的日期;或者計算距現在為 45 分鐘的時間。 為了對 date 加上“日”,可以使用“一年的日數” (“y”),“日” (”d”) 或“一周的日數” (”w”)。 DateAdd 函數将不傳回有效日期。在以下執行個體中将 1 月31 日加上一個月: DateAdd(m, 1, 31-Jan-95) 上例中,DateAdd 傳回 1995 年 2 月 28 日,而不是 1995 年 2 月 31 日。如果 date 是 1996 年 1 月 31 日,則由于 1996 年是閏年,傳回值是 1996 年 2 月 29 日。 如果計算的日期超前 100 年(減去的年度超過 date 中的年份),就會導緻錯誤發生。 如果 number 不是一個 Long 值,則在計算時取最接近的整數值來計算。 注意   DateAdd 傳回值的格式由 Control Panel設定決定,而不是由傳遞到date 參數的格式決定。 DateAdd 函數示例 本示例先取得一個日期,再用 DateAdd 函數顯示未來數月後的日期。  Dim FirstDate As Date    ’ 聲明變量。 Dim IntervalType As String Dim Number As Integer Dim Msg IntervalType = "m"    ’ "m"指定以“月份”作為間隔。 FirstDate = InputBox("Enter a date") Number = InputBox("Enter number of months to add") Msg = "New date: " & DateAdd(IntervalType, Number, FirstDate) MsgBox Msg -------------------------------------------------------------------------------- DateDiff 函數        傳回 Variant (Long) 的值,表示兩個指定日期間的時間間隔數目。 文法 DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]]) DateDiff 函數文法中有下列命名參數: 部分 描述  interval 必要。字元串表達式,表示用來計算date1 和 date2 的時間差的時間間隔  Date1□date2 必要;Variant (Date)。計算中要用到的兩個日期。  Firstdayofweek 可?gt;>V付ㄒ桓鲂瞧诘牡谝惶斓某JH绻從柚付ǎ蛞孕瞧谌瘴谝惶臁?nbsp; firstweekofyear 可?gt;>V付ㄒ荒甑牡谝恢艿某JH绻從柚付ǎ蛞園?nbsp;1 月 1 日的星期為第一周。  設定 interval 參數的設定值如下: 設定 描述  yyyy 年  q 季  m 月  y 一年的日數  d 日  w 一周的日數  ww 周  h 時  n 分鐘  s 秒  firstdayofweek 參數的設定值如下: 常數 值 描述  vbUseSystem 0 使用 NLS API 設定。  vbSunday 1 星期日(預設值)  vbMonday 2 星期一  vbTuesday 3 星期二  vbWednesday 4 星期三  vbThursday 5 星期四  vbFriday 6 星期五  vbSaturday 7 星期六  常數 值 描述  vbUseSystem 0 用 NLS API 設定。  vbFirstJan1 1 從包含 1 月 1 日的星期開始(預設值)。  vbFirstFourDays 2 從第一個其大半個星期在新的一年的一周開始。  vbFirstFullWeek 3 從第一個無跨年度的星期開始。  說明 DateDiff 函數可用來決定兩個日期之間所指定的時間間隔數目。例如,可以使用 DateDiff 來計算兩個日期之間相隔幾日,或計算從今天起到年底還有多少個星期。 為了計算 date1 與 date2 相差的日數,可以使用“一年的日數”(y) 或“日”(d)。當 interval 是“一周的日數”(w) 時,DateDiff 傳回兩日期間的周數。如果 date1 是星期一,DateDiff 計算到 date2 為止的星期一的個數。這個數包含 date2 但不包含 date1。不過,如果 interval 是“周”(ww),則 DateDiff 函數傳回兩日期間的“月曆周”數。由計算 date1 與 date2 之間星期日的個數而得。如果 date2 剛好是星期日,則 date2 也會被加進 DateDiff 的計數結果中;但不論 date1 是否為星期日,都不将它算進去。 如果 date1 比 date2 來得晚,則 DateDiff 函數的傳回值為負數。 firstdayofweek 參數會影響使用時間間隔符号 “W” 或 “WW” 計算的結果。 如果 date1 或 date2 是日期文字,則指定的年份成為該日期的固定部分。但是,如果 date1 或 date2 用雙引号 (" ") 括起來,且年份略而不提,則在每次計算表達式 date1 或 date2 時,目前年份都會插入到代碼之中。這樣就可以書寫适用于不同年份的程式代碼。 在計算 12 月 31 日和來年的 1 月 1 日的年份差時,DateDiff 傳回 1 表示相差一個年份,雖然實際上隻相差一天而已。 DateDiff 函數示例 本示例使用 DateDiff 函數來顯示某個日期與今日相差幾天。 Dim TheDate As Date    ’ 聲明變量。 Dim Msg TheDate = InputBox("Enter a date") Msg = "Days from today: " & DateDiff("d", Now, TheDate) MsgBox Msg -------------------------------------------------------------------------------- DatePart 函數        傳回一個包含已知日期的指定時間部分的 Variant (Integer)。 文法 DatePart(interval, date[,firstdayofweek[, firstweekofyear]]) DatePart 函數文法中有下列命名參數: 部分 描述  interval 必要。字元串表達式,是要傳回的時間間隔。  date 必要。要計算的 Variant (Date) 值。  Firstdayofweek 可?gt;>V付ㄒ桓鲂瞧诘牡谝惶斓某JH绻從柚付ǎ蛞孕瞧谌瘴谝惶臁?nbsp; firstweekofyear 可?gt;>V付ㄒ荒甑谝恢艿某JH绻從柚付ǎ蛞園?nbsp;1 月 1 日的星期為第一周。  設定 interval 參數的設定值如下: 設定 描述  yyyy 年  q 季  m 月  y 一年的日數  d 日  w 一周的日數  ww 周  h 時  n 分鐘  s 秒  firstdayofweek 參數的設定值如下: 常數 值 描述  vbUseSystem 0 使用 NLS API 設定。  vbSunday 1 星期日(預設值)  vbMonday 2 星期一  vbTuesday 3 星期二  vbWednesday 4 星期三  vbThursday 5 星期四  vbFriday 6 星期五  vbSaturday 7 星期六  firstweekofyear 參數的設定值如下: 常數 值 描述  vbUseSystem 0 使用 NLS API 設定。  vbFirstJan1 1 從包含 1 月 1 日的星期開始(預設值)。  vbFirstFourDays 2 從第一個其大半個星期在新的一年的一周開始。  vbFirstFullWeek 3 從第一個無跨年度的星期開始。  說明 DatePart 函數可以用來計算日期并傳回指定的時間間隔。例如,可以使用DatePart 計算某個日期是星期幾或目前為幾點鐘。 firstdayofweek 參數會影響使用時間間隔符号 “W” 或 “WW” 計算的結果。 如果 date 是日期文字,則指定的年份成為該日期的固定部分。但是,如果 date 用雙引号 (" ") ㄆ鹄矗夷攴萋遠惶幔蛟诿看渭撲?nbsp;date 表達式時,目前年份都會插入到代碼之中。這樣就可以書寫适用于不同年份的程式代碼。