日付時刻:年・月・日を取得(Year、Month、Day 関数)
日付から年・月・日を取得する関数
【書式】
date_year = Year ( date )
date_month = Month ( date )
date_day = Day ( date )
【引数・戻り値】
- date ・・・ 日付をあらわす値・文字列・数式
- date_year ・・・ 年を表すバリアント型(内部処理形式 Integer)の値
- date_month ・・・ 月(1~12 の範囲の整数)を表すバリアント型(内部処理形式 Integer)の値
- date_day ・・・ 日(1~31 の範囲の整数)を表すバリアント型(内部処理形式 Integer)の値
引数の date に有効でない値を指定するとエラーになります。
日付から年・月・日を取得する関数の使用例
サンプルVBAソース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
Sub Sample_YearMonthDay() Dim myDate1, myDate2, myDate3, myDate4, mydate5 Dim myNumber As Long myDate1 = "2015年10月1日" myDate2 = #11/30/1999# myDate3 = "2000-2-1" myDate4 = "H23/5/20" mydate5 = "昭和59年8月25日" myNumber = 36955 Debug.Print Year(myDate1) Debug.Print Year(myDate2) Debug.Print Year(myDate3) Debug.Print Year(myDate4) Debug.Print Year(mydate5) Debug.Print Year(myNumber) Debug.Print Year(0) Debug.Print Debug.Print Month(myDate1) Debug.Print Month(myDate2) Debug.Print Month(myDate3) Debug.Print Month(myDate4) Debug.Print Month(mydate5) Debug.Print Month(myNumber) Debug.Print Month(0) Debug.Print Debug.Print Day(myDate1) Debug.Print Day(myDate2) Debug.Print Day(myDate3) Debug.Print Day(myDate4) Debug.Print Day(mydate5) Debug.Print Day(myNumber) Debug.Print Day(0) End Sub |
実行結果
関連記事
-
-
変数がEmpty 値かどうかをチェックする( IsEmpty 関数 )
IsEmpty 関数の使い方 【書式】 result = IsEmpty ( e …
-
-
日付時刻:日付時刻データを計算( DateAdd 関数 )
DateAdd 関数(日付・時刻の値を加算・減算結果を取得) 【書式】 resu …
-
-
Math 関数( Abs,Atn,Cos,Exp,Log,Rnd,Sgn,Sin,Sqr,Tan )
Abs 関数 【書式】 value = Abs ( number ) 【引数・戻 …
-
-
指定したセル範囲のサイズを変更(Resize プロパティ)
Resize プロパティ 指定したセル範囲のサイズ(行数や列数)を変更します。 …
-
-
変数が数値型かどうかをチェックする( IsNumeric 関数 )
IsNumeric 関数の使い方 【書式】 result = IsNumeric …
-
-
VBA の演算子(算術演算子)
算術演算子 算術演算を行うときに使用する演算子です。 ^(べき乗)、*(積)、/ …
-
-
文字列:アルファベットを小文字または大文字に変換(LCase 関数,UCase 関数)
LCase 関数・UCase 関数 の使い方 【書式】 <アルファベットの大文字 …
-
-
VBA で正規表現を使う(RegExp オブジェクト)
RegExp オブジェクト VBA で正規表現を使うには、VBScript のR …
-
-
文字列:文字列の空白を削除(Trim 関数, LTrim関数, RTrim関数)
Trim 関数・LTrim 関数・RTrim 関数の使い方 【書式】 <先頭と末 …
-
-
ある数値が、複数の範囲のどの範囲に含まれるかを示す文字列を返す(Partition 関数)
Partition 関数 の使い方 Partition 関数は、ある数値が、区切 …