2
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 3 years have passed since last update.

UiPathで「今日からn日前」を1行で書く

Posted at

はじめに

仕事で「今日より10日前のファイルを○○する」とか、結構使うんですが、
いまいち覚えられないのでメモに残します。

AddDaysを使う

実際に書いてみます。
今日の10日前の日付をコンソールに出力するだけ。

コードはこんな感じです。

Now.AddDays(-10).ToString("yyyyMMdd")

image.png

結果

想定通り、今日(3/24)の10日前の日付である3/14がyyyyMMdd形式で出力されました。

image.png

月をまたぐ場合

月をまたぐ場合でも、ちゃんと出力されます。
以下のようにコードを変えたとします。

Now.AddDays(-32).ToString("yyyyMMdd")

これを実行してみると…

image.png

ちゃんと月をまたぐ場合でも、32日前の2/20が出力されました!!

非常に楽な日付操作方法ですので、今後はこれを使っていこうと思います。

2
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
2
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?