日付時刻:文字列から日付・時刻データを取得( DateValue 関数、TimeValue 関数 )
DateValue 関数(文字列から日付データを取得)
【書式】
date_value = DateValue ( date )
引数・戻り値
- date ・・・ 日付を表す文字列を指定します(※ 数値のみを指定するとエラーになります)。
(指定例)”2011/12/30″、”12/1/30″、”平成25年10月12日”、”H3-12-30″、”2015年1月” - date_value ・・・ 引数 date に指定した文字列に対応するバリアント型(内部処理形式 Date)の値。
TimeValue 関数(文字列から時刻データを取得)
【書式】
time_value = TimeValue ( time )
引数・戻り値
- time ・・・ 時刻を示す文字列を指定します。
(指定例)”11:30″、”3時56分15秒”、”平成25年10月12日 12時10分”、”午後2時11分”、”2015/3/4 1:30:26 PM”
(※ 日付も指定することも可能ですが戻り値には含まれません) - time_value ・・・ 引数 time に指定した文字列に対応するバリアント型(内部処理形式 Date)の値。
DateValue 関数、TimeValue 関数 の使用例
サンプル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 |
Sub Sample_GetDateTime() ' DateValue 関数 Debug.Print DateValue("2015年1月") Debug.Print DateValue("1月12日") Debug.Print DateValue("H13-10-30") Debug.Print DateValue("平成25年10月12日 12時10分") ' TimeValue 関数 Debug.Print TimeValue("11:30") Debug.Print TimeValue("3時56分15秒") Debug.Print TimeValue("平成25年10月12日 12時10分") Debug.Print TimeValue("午後2時11分") Debug.Print TimeValue("2015/3/4 1:30:26 PM") Debug.Print TimeValue("7:09 PM") End Sub |
実行結果
関連記事
-
-
変数が数値型かどうかをチェックする( IsNumeric 関数 )
IsNumeric 関数の使い方 【書式】 result = IsNumeric …
-
-
オブジェクトの書式をクリアする(ClearFormats メソッド)
ClearFormats メソッド 対象となるオブジェクトの書式(スタイル)を初 …
-
-
インプットボックスを表示する(InputBox関数・InputBoxメソッド)
「InputBox関数」と「InputBoxメソッド」の違い 「InputBox …
-
-
VBA の演算子(比較演算子)
比較演算子 比較演算子による演算の結果は「真」の場合は「True」、「偽」の場合 …
-
-
Split 関数(文字列型の一次配列を作成)
Split 関数の使い方 【書式】 myArray = Split ( expr …
-
-
文字に下線を設定する(Underline プロパティ)
下線を設定(Underline プロパティ) Underline プロパティは、 …
-
-
文字列:文字を指定数並べた文字列を返す(String 関数)
String 関数 【書式】 result = String ( number, …
-
-
Math 関数( Abs,Atn,Cos,Exp,Log,Rnd,Sgn,Sin,Sqr,Tan )
Abs 関数 【書式】 value = Abs ( number ) 【引数・戻 …
-
-
文字列:文字列を最後から検索してその最初の文字位置を返す(InStrRev 関数)
InStrRev 関数 任意の文字列の中で、指定した文字列を最後から検索して、見 …
-
-
変数がEmpty 値かどうかをチェックする( IsEmpty 関数 )
IsEmpty 関数の使い方 【書式】 result = IsEmpty ( e …
