日付時刻:時・分・秒を取得(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 |
日付リテラル/時刻リテラル :「#」で日付や時刻を囲む表示形式のこと
実行結果
関連記事
-
-
日付時刻:経過時間を取得( Timer 関数 )
Timer 関数の使い方 【書式】 result = Timer () 【戻り値 …
-
-
インプットボックスを表示する(InputBox関数・InputBoxメソッド)
「InputBox関数」と「InputBoxメソッド」の違い 「InputBox …
-
-
変数がEmpty 値かどうかをチェックする( IsEmpty 関数 )
IsEmpty 関数の使い方 【書式】 result = IsEmpty ( e …
-
-
カレントフォルダ(CurDir 関数、ChDir ステートメント、ChDrive ステートメント)
カレントフォルダ カレントフォルダとは、ブックを開いたり保存するときに既定で参照 …
-
-
文字列:文字列の一部を別の文字列で置換(Replace 関数)
Replace 関数の使い方 【書式】 result = Replace ( s …
-
-
配列の要素数を取得する(UBound 関数・LBound 関数)
UBound 関数・LBound 関数 【書式】 result = UBound …
-
-
文字列:文字列を最後から検索してその最初の文字位置を返す(InStrRev 関数)
InStrRev 関数 任意の文字列の中で、指定した文字列を最後から検索して、見 …
-
-
ユーザー定義定数(Const ステートメント)
定数を使う ユーザー定義の定数を使用するには、Const ステートメントを使って …
-
-
文字列:文字列変数内の一部を置き換える(Mid・MidB ステートメント)
Mid・MidB ステートメントの使い方 【書式】 { Mid | MidB } …
-
-
書式を変換(Format 関数)
Format 関数の使い方 【書式】 result = Format ( exp …