0
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 1 year has passed since last update.

ダイアログで日付設定

Last updated at Posted at 2022-05-29

概要

パイソン初心者です。
処理を自動化する際に、日付をインプットに作業したいことがあったので、
日付入力をするダイアログを作成。
デフォルトで前営業日(祝日は考慮しない)を設定します。

import tkinter.simpledialog as simpledialog
import datetime

def pre_business_day(date):
    """ 前営業日を取得(祝日は考慮しない) """
    # 月曜日の場合
    if datetime.date.weekday(date) == 0 :
        pre = date - datetime.timedelta(days=3)
    # 日曜日の場合
    elif datetime.date.weekday(date) == 6 :
        pre = date - datetime.timedelta(days=2)
    else:
        pre = date-datetime.timedelta(days=1)
    return pre

initDate = pre_business_day(datetime.datetime.now())
inputDateText = simpledialog.askstring('日付入力', '入力日', initialvalue=format(initDate, '%Y/%m/%d'))
inputDate = datetime.datetime.strptime(inputDateText, '%Y/%m/%d')
print(inputDate)

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