<bdo id='7Ithk'></bdo><ul id='7Ithk'></ul>
        <i id='7Ithk'><tr id='7Ithk'><dt id='7Ithk'><q id='7Ithk'><span id='7Ithk'><b id='7Ithk'><form id='7Ithk'><ins id='7Ithk'></ins><ul id='7Ithk'></ul><sub id='7Ithk'></sub></form><legend id='7Ithk'></legend><bdo id='7Ithk'><pre id='7Ithk'><center id='7Ithk'></center></pre></bdo></b><th id='7Ithk'></th></span></q></dt></tr></i><div id='7Ithk'><tfoot id='7Ithk'></tfoot><dl id='7Ithk'><fieldset id='7Ithk'></fieldset></dl></div>

        <tfoot id='7Ithk'></tfoot>
      1. <small id='7Ithk'></small><noframes id='7Ithk'>

        <legend id='7Ithk'><style id='7Ithk'><dir id='7Ithk'><q id='7Ithk'></q></dir></style></legend>
      2. 将 Python 中的日期与 datetime 进行比较

        时间:2023-11-07
      3. <small id='5mZrU'></small><noframes id='5mZrU'>

          <tbody id='5mZrU'></tbody>

          <tfoot id='5mZrU'></tfoot>
            <i id='5mZrU'><tr id='5mZrU'><dt id='5mZrU'><q id='5mZrU'><span id='5mZrU'><b id='5mZrU'><form id='5mZrU'><ins id='5mZrU'></ins><ul id='5mZrU'></ul><sub id='5mZrU'></sub></form><legend id='5mZrU'></legend><bdo id='5mZrU'><pre id='5mZrU'><center id='5mZrU'></center></pre></bdo></b><th id='5mZrU'></th></span></q></dt></tr></i><div id='5mZrU'><tfoot id='5mZrU'></tfoot><dl id='5mZrU'><fieldset id='5mZrU'></fieldset></dl></div>

              <bdo id='5mZrU'></bdo><ul id='5mZrU'></ul>

                <legend id='5mZrU'><style id='5mZrU'><dir id='5mZrU'><q id='5mZrU'></q></dir></style></legend>
                  本文介绍了将 Python 中的日期与 datetime 进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  So I have a list of dates:

                  [datetime.date(2013, 7, 9), datetime.date(2013, 7, 12), datetime.date(2013, 7, 15), datetime.date(2013, 7, 18), datetime.date(2013, 7, 22), datetime.date(2013, 7, 25)]
                  

                  And I know today is:

                  date.today() 
                  

                  For the sake of this post, today is datetime.date(2013, 7, 15)

                  I need to be able to generate a list of any future dates, including today if it's on the list.

                  The return statement would be:

                  [datetime.date(2013, 7, 15), datetime.date(2013, 7, 18), datetime.date(2013, 7, 22), datetime.date(2013, 7, 25)]
                  

                  I know I can just iterate over a list and compare dates using a timedelta but there has to be an easier way..

                  解决方案

                  Comparing date with other date is possible.

                  date1 < date2 date1 is considered less than date2 when date1 precedes date2 in time.

                  >>> datetime.date(2013, 7, 15) < datetime.date(2013, 7, 16)
                  True
                  >>> datetime.date(2013, 7, 15) <= datetime.date(2013, 7, 16)
                  True
                  >>> datetime.date(2013, 7, 15) > datetime.date(2013, 7, 16)
                  False
                  


                  >>> import datetime
                  >>> today = datetime.date(2013, 7, 15) # datetime.date.today()
                  >>> [d for d in dates if d >= today]
                  [datetime.date(2013, 7, 15), datetime.date(2013, 7, 18), datetime.date(2013, 7, 22), datetime.date(2013, 7, 25)]
                  

                  这篇关于将 Python 中的日期与 datetime 进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:python - 将字符串中的日期与今天的日期进行比较 下一篇:pandas 将值与前一行与过滤条件进行比较

                  相关文章

                • <small id='Cq7Pd'></small><noframes id='Cq7Pd'>

                  <i id='Cq7Pd'><tr id='Cq7Pd'><dt id='Cq7Pd'><q id='Cq7Pd'><span id='Cq7Pd'><b id='Cq7Pd'><form id='Cq7Pd'><ins id='Cq7Pd'></ins><ul id='Cq7Pd'></ul><sub id='Cq7Pd'></sub></form><legend id='Cq7Pd'></legend><bdo id='Cq7Pd'><pre id='Cq7Pd'><center id='Cq7Pd'></center></pre></bdo></b><th id='Cq7Pd'></th></span></q></dt></tr></i><div id='Cq7Pd'><tfoot id='Cq7Pd'></tfoot><dl id='Cq7Pd'><fieldset id='Cq7Pd'></fieldset></dl></div>
                  <tfoot id='Cq7Pd'></tfoot>
                  • <bdo id='Cq7Pd'></bdo><ul id='Cq7Pd'></ul>
                  <legend id='Cq7Pd'><style id='Cq7Pd'><dir id='Cq7Pd'><q id='Cq7Pd'></q></dir></style></legend>