やじゅ@アプリケーション・ラボ わんくま支局

目次

Blog 利用状況

ニュース

プロフィール

MSMVP

Windowsバッチで日付計算を簡単に行う

これは、Visual Basic Advent Calendar 2015の12/1日の記事。

現在、会社では運用チームに属しています。
バッチファイルやVBScriptを使って導入作業やバックアップなどの仕組みを作ることが増えました。

バッチコマンドで日付計算する処理を作ろうとすると結構面倒です。VBScriptではDateAdd関数の1ステートメントで済むのに。
ネットで検索して出てくる処理も思っているより長く書かれているので組み込むのは躊躇してしまいまいます。
そんな中でもいい方法を提示していたのを見つけました。

バッチファイルで昨日の日付を取得
http://oshiete.goo.ne.jp/qa/3597882.html

日付時刻計算はVBScriptを使ってしまうのが楽です。
echo WScript.Echo DateAdd("d",-1,Date()) > tmp.vbs
for /f "tokens=1-3 delims=/-" %%A in ('cscript //nologo tmp.vbs') do set ANS=%%A%%B%%C
del tmp.vbs

なるほどね。一時的にVBScriptを作成し計算結果を取得してしまうと。
これなら日付処理に関わらず応用がいろいろ出来そうです。

投稿日時 : 2015年12月1日 2:02

コメントを追加

# I'm truly enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Fantastic work! 2018/09/21 18:26 I'm truly enjoying the design and layout of your w

I'm truly enjoying the design and layout of your website.
It's a very easy on the eyes which makes it much more pleasant for
me to come here and visit more often. Did you hire out a developer to create your theme?
Fantastic work!

# Everyone loves it when individuals come together and share thoughts. Great blog, keep it up! 2018/10/05 7:47 Everyone loves it when individuals come together a

Everyone loves it when individuals come together and share thoughts.

Great blog, keep it up!

# I'm not sure where you are getting your information, but good topic. I needs to spend some time learning much more or understanding more. Thanks for magnificent info I was looking for this info for my mission. 2019/04/07 14:11 I'm not sure where you are getting your informatio

I'm not sure where you are getting your information, but good topic.
I needs to spend some time learning much more or understanding more.

Thanks for magnificent info I was looking for this info for my mission.

# I always emailed this web site post page to all my contacts, for the reason that if like to read it after that my links will too. 2019/05/03 6:03 I always emailed this web site post page to all my

I always emailed this web site post page to all my contacts, for the reason that if like to read it after
that my links will too.

# It's impressive that you are getting ideas from this post as well as from our dialogue made at this place. 2019/05/08 5:04 It's impressive that you are getting ideas from th

It's impressive that you are getting ideas from this post as well as
from our dialogue made at this place.

# I like the valuable info you provide in your articles. I'll bookmark your weblog and check again here regularly. I am slightly sure I'll be informed a lot of new stuff right right here! Good luck for the following! 2019/05/12 0:33 I like the valuable info you provide in your artic

I like the valuable info you provide in your articles.
I'll bookmark your weblog and check again here regularly.
I am slightly sure I'll be informed a lot of new stuff
right right here! Good luck for the following!

# wonderful points altogether, you just won a brand new reader. What might you suggest in regards to your publish that you just made some days in the past? Any positive? 2019/07/01 22:32 wonderful points altogether, you just won a brand

wonderful points altogether, you just won a brand new reader.
What might you suggest in regards to your publish that you just made some days in the past?
Any positive?

# Wonderful post! We are linking to this great post on our site. Keep up the good writing. 2019/08/01 15:49 Wonderful post! We are linking to this great post

Wonderful post! We are linking to this great post on our site.
Keep up the good writing.

# Wonderful post! We are linking to this great post on our site. Keep up the good writing. 2019/08/01 15:50 Wonderful post! We are linking to this great post

Wonderful post! We are linking to this great post on our site.
Keep up the good writing.

# Wonderful post! We are linking to this great post on our site. Keep up the good writing. 2019/08/01 15:51 Wonderful post! We are linking to this great post

Wonderful post! We are linking to this great post on our site.
Keep up the good writing.

# Wonderful post! We are linking to this great post on our site. Keep up the good writing. 2019/08/01 15:52 Wonderful post! We are linking to this great post

Wonderful post! We are linking to this great post on our site.
Keep up the good writing.

# Great blog you have got here.. It's difficult to find quality writing like yours these days. I honestly appreciate individuals like you! Take care!! 2019/08/19 0:47 Great blog you have got here.. It's difficult to f

Great blog you have got here.. It's difficult to find
quality writing like yours these days. I honestly appreciate individuals like you!
Take care!!

# Great blog you have got here.. It's difficult to find quality writing like yours these days. I honestly appreciate individuals like you! Take care!! 2019/08/19 0:48 Great blog you have got here.. It's difficult to f

Great blog you have got here.. It's difficult to find
quality writing like yours these days. I honestly appreciate individuals like you!
Take care!!

# Great blog you have got here.. It's difficult to find quality writing like yours these days. I honestly appreciate individuals like you! Take care!! 2019/08/19 0:49 Great blog you have got here.. It's difficult to f

Great blog you have got here.. It's difficult to find
quality writing like yours these days. I honestly appreciate individuals like you!
Take care!!

# Great blog you have got here.. It's difficult to find quality writing like yours these days. I honestly appreciate individuals like you! Take care!! 2019/08/19 0:50 Great blog you have got here.. It's difficult to f

Great blog you have got here.. It's difficult to find
quality writing like yours these days. I honestly appreciate individuals like you!
Take care!!

# Hi there, everything is going perfectly here and ofcoursse every one is sharing facts, that's really fine, keep up writing. 2019/10/20 21:34 Hi there, everything is going perfectly here and f

Hi there, everything is going perfectly here and ofcourse every
onee is sharing facts, that's reallky fine, keep up writing.

# Hi my family member! I want to say that this article is amazing, great written and include almost all vital infos. I would like to look extra posts like this . 2019/11/17 19:43 Hi my family member! I want to say that this artic

Hi my family member! I want to say that this article is amazing,
great written and include almost all vital infos.
I would like to look extra posts like this .

# Wow that was strange. I just wrote an very long comment but after I clicked submit my comment didn't show up. Grrrr... well I'm not writing all that over again. Anyhow, just wanted to say great blog! 2019/11/24 17:08 Wow that was strange. I just wrote an very long co

Wow that was strange. I just wrote an very long comment
but after I clicked submit my comment didn't show up.

Grrrr... well I'm not writing all that over again. Anyhow, just wanted
to say great blog!

タイトル  
名前  
URL
コメント