日付時刻:時・分・秒を取得(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 |
日付リテラル/時刻リテラル :「#」で日付や時刻を囲む表示形式のこと
実行結果
関連記事
-
-
文字列:指定した数の空白(スペース)からなる文字列を返す(Space 関数)
Space 関数 【書式】 result = Space ( number ) …
-
-
変数が数値型かどうかをチェックする( IsNumeric 関数 )
IsNumeric 関数の使い方 【書式】 result = IsNumeric …
-
-
文字列:文字列の一部を別の文字列で置換(Replace 関数)
Replace 関数の使い方 【書式】 result = Replace ( s …
-
-
ショートカットメニュー(CommandBar オブジェクト)
ショートカットメニュー(コンテキストメニュー) 右クリックで表示されるメニューの …
-
-
セルのデータを区切り文字で複数のセルに分割する(TextToColumns メソッド)
TextToColumns メソッド TextToColumns メソッドを使用 …
-
-
指定した数値を文字列に変換する(Str 関数)
Str 関数 の使い方 Str 関数は、数値・数式を文字列に変換して返す関数です …
-
-
文字列:文字列右から指定文字数取得(Right 関数,RightB 関数)
Right 関数・RightB 関数 の使い方 【書式】 result_righ …
-
-
配列の要素数を取得する(UBound 関数・LBound 関数)
UBound 関数・LBound 関数 【書式】 result = UBound …
-
-
VBA の演算子(演算子の優先順位)
演算子の優先順位 演算子の優先順位とは、1つの式の中に演算子が複数ある場合、どの …
-
-
データをクリアする(ClearContents メソッド)
ClearContents メソッド 対象がセル範囲(Range オブジェクト) …
