ÆÄÀ̽㠳¯Â¥°ª Áú¹®

doping   
   Á¶È¸ 3137   Ãßõ 0    

 https://stackoverflow.com/questions/546321/how-do-i-calculate-the-date-six-months-from-the-current-date-using-the-datetime?page=2&tab=votes#tab-top


---------------------------------------------------

from datetime import date


def after_month(given_date, month):

    yyyy = int(((given_date.year * 12 + given_date.month) + month)/12)

    mm = int(((given_date.year * 12 + given_date.month) + month)%12)


    if mm == 0:

        yyyy -= 1

        mm = 12

    return given_date.replace(year=yyyy, month=mm)


 print(next_date, end = ' ')

-----------------------------------------------------

링크에서 처럼 현재를 입력하고 한달후를 출력하고 싶으면 위코드에 무엇을 추가하고 수정해줘야 할까요?

ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
Krepe 2021-04
º»¹®¿¡ ¾²½Å url µé¾î°¡¼­ º¸´Ï dateutil.relativedelta ¸¦ ÀÓÆ÷Æ®Çؼ­ date °´Ã¼¿¡ relativedelta(months=1) ¸¦ ´õÇÏ´Â ¹æ¹ýÀÌ Á÷Á¢ °è»êÇÒ ÇÊ¿ä ¾øÀÌ ±ò²ûÇÏ°Ô ±¸ÇöÀÌ µÉ°Å°°Àºµ¥ º°µµÀÇ ¸ðµâ »ç¿ë ¾øÀÌ °è»êÀ» ÇؾßÇϴ°ǰ¡¿ä?
     
doping 2021-04
from datetime import date



def after_month(given_date, month):

    yyyy = int(((given_date.year * 12 + given_date.month) + month)/12)

    mm = int(((given_date.year * 12 + given_date.month) + month)%12)



    if mm == 0:

        yyyy -= 1

        mm = 12

    return given_date.replace(year=yyyy, month=mm)



 print(next_date, end = ' ')

À§ Äڵ带 ¼öÁ¤Çؼ­ °ªÀ» ³ªÅ¸³»·Á°í Çϴµ¥, ÁÁÀº ¹æ¹ýÀÌ ÀÖÀ¸½Å°¡¿ä?
¹«¾Æ 2021-04
¾îÁ¦µµ ¹°¾îº¸°í ´äº¯ÇÏ¸é ±ÛÁö¿ì°í... ±Û Áö¿ï°Å ¿Ö ¹¯³ª¿ä?

¿©±â¼­ µÎ³ú ±â¸§Ä¥ ÄûÁî.

1¿ù 31ÀÏÀÇ ÇÑ ´Þ ÈÄ´Â ¸î ÀÏ Àϱî¿ä?
     
doping 2021-04
´äÇØÁֽŠ¹«¾Æ´Ô²²´Â °¨»çµå¸®Áö¸¸ ¾îÁ¦´Â Áú¹®¹æÇâµµ À߸øÁ¤ÇÏ°í ºñ¾Æ³É´ñ±ÛÀÌ ÀÖ¾î Áö¿ü³×¿ä ¤Ì¤Ì 3¿ù2ÀÏÀΰ¡¿ä??
          
¹«¾Æ 2021-04
À§¿¡ ÄÚµå·Î´Â 2¿ù 31ÀÏ·Î µÉ °ÍÀÌ°í 2¿ù 31ÀÏÀº Á¸ÀçÇÏÁö ¾Ê¾Æ¼­ ¾îÁ¦ÀÇ ±× ¿¡·¯°¡ ¶á °Ì´Ï´Ù.

ÇÑ ´ÞÀÇ °³³äÀ» 30ÀÏ °ú °°ÀÌ ³¯Â¥ °³³äÀ¸·Î Àâ´Â´Ù¸é ´Þ ´ÜÀ§°¡ ¾Æ´Ñ ³¯Â¥ ´ÜÀ§ÀÇ ¿¬»êÀ» ÇÏ´Â°Ô ¸Â°í
´ÞÀÇ ¸íĪÀ» °¡Áö°í °è»êÇÑ´Ù¸é ÇØ´ç ´Þ¿¡ Ç¥ÇöµÉ ¼ö ¾ø´Â ³¯Â¥¿¡ ´ëÇÑ ¿¹¿Ü 󸮸¦ µÎ´Â °ÍÀÌ ¸ÂÁÒ.
±×³É ÀÌ´ë·Îµµ Àß °è»êÇÏ´Â °Íó·³ º¸À̳׿ä.

import datetime
from datetime import date

def after_month(given_date, month):
    yyyy = int(((given_date.year * 12 + given_date.month) + month)/12)
    mm = int(((given_date.year * 12 + given_date.month) + month)%12)
    if mm == 0:
        yyyy -= 1
        mm = 12
    return given_date.replace(year=yyyy, month=mm)

today = datetime.datetime.today()
print("today:", today)
print("after 1 month:", after_month(today, 1))

===

°á°ú´Â ¾Æ·¡¿Í °°³×¿ä.

today: 2021-04-21 22:23:12.109035
after 1 month: 2021-05-21 22:23:12.109035
     
doping 2021-04
±×·³ Ȥ½Ã ÇöÀç ³¯Â¥¸¦ ÁöÁ¤Çؼ­ Äڵ带 ¸¸µå·Á°íÇÑ´Ù¸é ¾î¶»°Ô ¼öÁ¤Çϸé ÁÁÀ»±î¿ä?
          
datetimeÀÇ constructor°¡ ¾Æ·¡¿Í °°À¸´Ï...
class datetime.datetime(year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)

datetime.datetime(2021, 04, 27) °°Àº ½ÄÀ¸·Î ¸¸µé¸é µÇ°Ú±º¿ä.

À§ÀÇ Äڵ忡
another_day = datetime.datetime(1999, 8, 18)
print("another_day:", another_day)
print("after 3 months:", after_month(another_day, 3))

ÀÌ·¸°Ô Ãß°¡Çϸé, °á°ú°¡ ¾Æ·¡Ã³·³ ³ª¿À³×¿ä.

~/workspace$ python3 next_month.py
today: 2021-04-27 01:48:29.779192
after 1 month: 2021-05-27 01:48:29.779192
another_day: 1999-08-18 00:00:00
after 3 months: 1999-11-18 00:00:00
ÇÑ ´Þ ÈÄÀÇ Á¤ÀǸ¦ ÇÏ´Â°Ô ¿ì¼±ÀÌÁö ¾ÊÀ»±î¿ä?
28ÀÏÀÎÁö, 30ÀÏÀÎÁö, ´Þ·Â»ó 1´Þ¸¸ À̵¿ÇÒ °ÍÀÎÁö µî¿¡ ´ëÇؼ­¿ä.
ÇöÀç°ªÀ» epoch·Î º¯È¯Çؼ­ °è»êÇÏ´Â ¹æ½ÄÀÌ ÆíÇÒ°Å °°³×¿ä.


QnA
Á¦¸ñPage 737/5680
2014-05   4946602   Á¤ÀºÁØ1
2015-12   1483267   ¹é¸Þ°¡
2003-07   9873   ÀÌÇÑ¿ë
2006-10   4911   ±èÀç½Ä
2004-09   6727   Á¤Å¼ö
2004-09   7259   ÃÖ¿ë¼®
2007-03   4534   ÀÌÈñõ
2006-01   5231   Á¤ÈûÂù
2006-10   4572   ¹ÚÁ¾´ë
2008-04   6149   ÁÖ¿ëÈÆ
2005-11   5381   ±è°Ç¿ì
2006-10   4252   Â÷Á¦¸í
2002-09   12756   È«½ÂÈ£
2008-09   4961   ±è½ÂÇö
2004-09   6925   ±èÀçÇå
2005-09   5820   ±èÀ¯°â
2006-01   5476   À±¿µ¹è
2006-11   4430   ¹ÎºÀ±â
2007-07   4972   ÀÌ»óÇå
2002-10   12689   俵Áø
2005-10   4846   ¿°Àçµµ
2005-05   5943   Çϼö¾ð