日付時刻:時・分・秒を取得(Hour、Minute、Second 関数)
日付時刻から時・分・秒を取得する関数
【書式】
time_hour = Hour ( time )
time_minute = Minute ( time )
time_second = Second ( time )
【引数・戻り値】
- time ・・・ 時刻をあらわす値・文字列・数式
- time_hour ・・・ 時刻(0~23 の範囲の整数)を表すバリアント型(内部処理形式 Integer)の値
- time_minute ・・・ 分(0~59 の範囲の整数)を表すバリアント型(内部処理形式 Integer)の値
- time_second ・・・ 秒(0~59 の範囲の整数)を表すバリアント型(内部処理形式 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 |
Sub Sample_HourMinuteSecond() Dim myDate1, myDate2 Dim myTime1, myTime2 myDate1 = #2/3/2011 2:30:20 AM# '日付リテラル myDate2 = "2015年1月1日19時20分" myTime1 = #5:04:23 PM# '時刻リテラル myTime2 = "午前6時" Debug.Print Hour(myDate1) Debug.Print Minute(myDate1) Debug.Print Second(myDate1) Debug.Print Debug.Print Hour(myDate2) Debug.Print Minute(myDate2) Debug.Print Second(myDate2) Debug.Print Debug.Print Hour(myTime1) Debug.Print Minute(myTime1) Debug.Print Second(myTime1) Debug.Print Debug.Print Hour(myTime2) Debug.Print Minute(myTime2) Debug.Print Second(myTime2) Debug.Print Hour(Time) 'Time 関数は、現在の時刻を取得 Debug.Print Minute(Now()) 'Now 関数は、現在の日付・時刻を取得 Debug.Print Second(Date) 'Date 関数は、現在の日付を取得 End Sub |
日付リテラル/時刻リテラル :「#」で日付や時刻を囲む表示形式のこと
実行結果
関連記事
-
-
ポイント単位の値に変換(CentimetersToPoints,InchesToPoints)
CentimetersToPoints メソッド センチメートル単位の値をポイン …
-
-
乱数を生成する(Rnd 関数)
Rnd 関数の使い方 Rnd 関数は、0 以上、1 未満の範囲の乱数を単精度浮動 …
-
-
XlThemeColor 列挙型
XlThemeColor 列挙 定数 値 内容 xlThemeColorDark …
-
-
対象のオブジェクトをクリアする(Clear メソッド)
Clear メソッド 対象となるオブジェクト全体をクリアします。Range オブ …
-
-
変数がEmpty 値かどうかをチェックする( IsEmpty 関数 )
IsEmpty 関数の使い方 【書式】 result = IsEmpty ( e …
-
-
VBAの変数宣言
VBAの変数宣言について 変数を暗黙的に宣言する エクセル VBA の場合、明示 …
-
-
指定した数値を文字列に変換する(Str 関数)
Str 関数 の使い方 Str 関数は、数値・数式を文字列に変換して返す関数です …
-
-
文字列:定数(改行・タブ)
改行・タブの定数 これらの定数は、使用前に定義する必要はありません。コード中のど …
-
-
文字列:文字列を指定した形式に変換する(StrConv 関数)
StrConv 関数の使い方 【書式】 result = StrConv ( s …
-
-
VBA の演算子(演算子の優先順位)
演算子の優先順位 演算子の優先順位とは、1つの式の中に演算子が複数ある場合、どの …