在 Python 中获取当前季度的第一个日期和最后一个日期? [英] Get First Date and Last Date of Current Quarter in Python?

查看:64
本文介绍了在 Python 中获取当前季度的第一个日期和最后一个日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Python 中获取当前季度年份,然后是当前季度年份的第一个日期和最后一个日期?

How can i get the Current Quarter year and then First Date and last Date of Current Quarter Year in Python?

我想通过导入日期时间

import datetime

人们研究堆栈溢出需要直接的答案,这应该非常简单.您提供的哪个链接有很多评论.因此,用户必须浏览所有评论才能找到正确答案.我正在写简单明了的答案.

People look into Stack overflow need straight forward answer and which should be very simple. Which ever link you provided it having lot of Comments. SO, users has to go through all the comments to find correct answer. I am writing simple and straight forward answer.

推荐答案

我如何在 c# 中找到一些简单的解决方案并将其转换为 python,

Any how i found some simple solution in c# and converted it into python,

from datetime import datetime,timedelta
current_date=datetime.now()
currQuarter = (current_date.month - 1) / 3 + 1
dtFirstDay = datetime(current_date.year, 3 * currQuarter - 2, 1)
dtLastDay = datetime(current_date.year, 3 * currQuarter + 1, 1) + timedelta(days=-1)

这篇关于在 Python 中获取当前季度的第一个日期和最后一个日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆