1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Q12.今日の日付をyyyymmdd形式で取得するには?

Last updated at Posted at 2020-01-19

例えば、ファイル名とかに取得したタイミングの日付を末尾につけたりするケースとかありますよね。
aaa_2020mmddみたいな感じでね。
当日の日付をyyyymmdd形式で取得するにはどうしたらいいでしょう?
実はVBAでは簡単に取得することができます。

今回は、単純に当日日付をダイアログで表示するだけのごくシンプルなマクロを作ってみましょう。

■回答

Sub Q12_Answer()
    MsgBox Format(Date, "yyyymmdd")
End Sub

■解説

Format関数を使うだけのシンプルなコードです。
Format関数を使うといろいろな形式で表現することができます。

例えば、yyyy/mm/ddといった区切りに/を使った表現とかね。

今回はファイル名でつけることを想定して考えたのでこのような形式にしています。

実行結果は以下です。(2020/01/19に実行しています。)

Q12.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?