常用函式 日期函式

2021-06-17 16:27:10 字數 1866 閱讀 1137

對日期的處理,一般在有日期限制的共享、商業軟體中經常使用到。如果你打算編寫一款有日期限制的軟體,熟悉使用下面的函式即可以實現。

1.date

功能說明:返回當前的日期。

procedure tform1.button1click(sender: tobject);

begin

label1.caption := '今天是:' +datetostr(date);

end;

label顯示為:今天是2023年1月1日。

2.datetostr

功能說明:將日期型轉換為字元型。

vars: string;

begin

s := datetostr(date);

end;

3.datetimetostr

功能說明:將datetime型轉換為字元型。

vars: string;

begin

s := datetimetostr(now);

end;

4.dayofthemonth(所在單元:dateutils)

功能說明:獲取指定日期的日。

label1.caption := inttostr(dayofthemonth(now));

假設當前日期為2023年1月2日,那麼label將顯示為2。

5.dayoftheweek(所在單元:dateutils)

功能說明:根據指定日期,獲取星期幾。

label1.caption := inttostr(dayofthemonth(now));

假設當前日期為2023年1月2日,那麼label將顯示為7。根據返回的值來判斷是週幾。7表示星期天,1為星期一,依類類推。

6.dayoftheyear(所在單元:dateutils)

功能說明:根據指定日期,獲取天數。

label1.caption := inttostr(dayoftheyear(now));

假設當前日期為2023年1月2日,那麼label將顯示為2。表示是2023年的第2天。

7.dayof(所在單元:dateutils)

功能說明:根據指定的日期,返回日。

label1.caption := inttostr(dayof(date));

假設當前日期為2023年1月2日,那麼label將顯示為2。

8.isleapyear

功能說明:根據指定的年,判斷是否為閏年。可使用yearof函式獲取年。

procedure tform1.button1click(sender: tobject);

begin

if isleapyear(yearof(date)) then showmessage('是閏年')

else showmessage('不是閏年');

end;

9.monthof(所在單元:dateutils)

功能說明:根據指定的日期,返回月份。

label1.caption := inttostr(monthof(date));

假設當前日期為2023年1月2日,那麼label將顯示為1。

10.now

功能說明:返回當前日期及時間。

procedure tform1.button1click(sender: tobject);

begin

label1.caption := '現在是:' +datetimetostr(now);

end;

11.yearof(所在單元:dateutils)

功能說明:根據指定的日期,返回年。

label1.caption := inttostr(yearof(date));

假設當前日期為2023年1月2日,那麼label將顯示為2005。

oracle 日期常用函式 日期運算

oracle 日期常用函式 日期運算 1日期運算 23 1.更改日期顯示的format 4ex.5alter session setnls date format yyyy mm dd 6階段作業已被更改 78 select sysdate from dual 910 sysdate 11 1220...

SAS函式 日期函式

一 日期的合併 將月 日 年合併為乙個日期格式的變數或值。mdy 月,日,年 注意 月,日,年的順序不能變。二 日期的差值 計算兩個日期之間以年為單位的差值 yrdif 開始日期,結束日期,計算依據 計算兩個日期之間以天為單位的差值 datdif 開始日期,結束日期,計算依據 計算依據 actual...

單行函式(日期函式)

oracle 預設的日期格式為 dd mon yyyy select sysdate from dual d 表示2位數的日 mon month 表示月份,如 6月 mm 表示2位數的月,如 06 yyyy 表示4位數的年份 hh24 表示24小時 hh 表示12小時 mi 表示分鐘 ss 表示秒 ...