日付時刻:時・分・秒を取得(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 |
日付リテラル/時刻リテラル :「#」で日付や時刻を囲む表示形式のこと
実行結果
関連記事
-
-
文字列:文字列左から指定文字数取得(Left 関数,LeftB 関数)
Left 関数・LeftB 関数 の使い方 【書式】 result_left = …
-
-
データをクリアする(ClearContents メソッド)
ClearContents メソッド 対象がセル範囲(Range オブジェクト) …
-
-
連想配列(Dictionary オブジェクト)
連想配列 連想配列とは、添字(キー)に文字列を使用することができる配列です。 V …
-
-
日付時刻:経過時間を取得( Timer 関数 )
Timer 関数の使い方 【書式】 result = Timer () 【戻り値 …
-
-
変数がNull 値かどうかをチェックする( IsNull 関数 )
IsNull 関数の使い方 【書式】 result = IsNull ( exp …
-
-
上付き文字・下付き文字(Superscript,Subscript)
上付き文字(Superscript プロパティ) Superscript プロパ …
-
-
VBA の演算子(論理演算子:And、Eqv、Imp、Not、Or、Xor)
論理演算子 論理演算を行うときに使用する演算子で、以下の 6 種類があります。 …
-
-
色を設定する(QBColor 関数)
QBColor 関数 QBColor 関数は、指定した色番号に対応するRGB コ …
-
-
色の設定(Color プロパティ・RGB 関数)
Color プロパティ Color プロパティは、指定したオブジェクトの色を取得 …
-
-
文字列:文字を指定数並べた文字列を返す(String 関数)
String 関数 【書式】 result = String ( number, …
