日付時刻:時・分・秒を取得(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 |
日付リテラル/時刻リテラル :「#」で日付や時刻を囲む表示形式のこと
実行結果
関連記事
-
-
文字列:文字列を指定した形式に変換する(StrConv 関数)
StrConv 関数の使い方 【書式】 result = StrConv ( s …
-
-
式を評価し、結果(真・偽)に応じた式・値を返す(IIf 関数)
IIf 関数 の使い方 IIf(アイイフ)関数は、式を評価してその結果(真・偽) …
-
-
データをクリアする(ClearContents メソッド)
ClearContents メソッド 対象がセル範囲(Range オブジェクト) …
-
-
指定した値を8進数で表記した文字列に変換する(Oct 関数)
Oct 関数 の使い方 【書式】 result = Oct ( expressi …
-
-
日付時刻:文字列から日付・時刻データを取得( DateValue 関数、TimeValue 関数 )
DateValue 関数(文字列から日付データを取得) 【書式】 date_va …
-
-
文字列:文字列を検索してその最初の文字位置を返す(InStr 関数,InStrB 関数)
InStr 関数・InStrB 関数の使い方 【書式】 result = { I …
-
-
データ型を調べて、そのデータ型を示す数値を返す(VarType 関数)
VarType 関数 の使い方 VarType 関数は、引数に、データ型を調べた …
-
-
日付時刻:経過時間を取得( Timer 関数 )
Timer 関数の使い方 【書式】 result = Timer () 【戻り値 …
-
-
VBA で正規表現を使う(RegExp オブジェクト)
RegExp オブジェクト VBA で正規表現を使うには、VBScript のR …
-
-
色の設定(Color プロパティ・RGB 関数)
Color プロパティ Color プロパティは、指定したオブジェクトの色を取得 …
