日付時刻:文字列から日付・時刻データを取得( 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 |
実行結果
関連記事
-
-
ユーザー定義関数:セルを取得する(ThisCell プロパティ)
入力されたセルを取得する ワークシート上で使用する Function プロシージ …
-
-
カレントフォルダの取得・設定(DefaultFilePath プロパティ)
DefaultFilePath プロパティ カレントフォルダとは、ブックを開いた …
-
-
コレクション(Collection)オブジェクト「連想配列」
コレクション(Collection)オブジェクトの使い方 【書式】 Dim my …
-
-
ポイント単位の値に変換(CentimetersToPoints,InchesToPoints)
CentimetersToPoints メソッド センチメートル単位の値をポイン …
-
-
ある数値が、複数の範囲のどの範囲に含まれるかを示す文字列を返す(Partition 関数)
Partition 関数 の使い方 Partition 関数は、ある数値が、区切 …
-
-
文字列:文字列の指定した位置から指定文字数取得(Mid 関数,MidB 関数)
Mid 関数・MidB 関数 の使い方 【書式】 result_mid = Mi …
-
-
文字列:指定した文字の文字コードを取得する(Asc 関数)
Asc 関数 【書式】 result = Asc ( string ) 引数・戻 …
-
-
上付き文字・下付き文字(Superscript,Subscript)
上付き文字(Superscript プロパティ) Superscript プロパ …
-
-
Split 関数(文字列型の一次配列を作成)
Split 関数の使い方 【書式】 myArray = Split ( expr …
-
-
対象のオブジェクトをクリアする(Clear メソッド)
Clear メソッド 対象となるオブジェクト全体をクリアします。Range オブ …
