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

doping   
   Á¶È¸ 3131   Ãßõ 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 734/5677
2014-05   4938078   Á¤ÀºÁØ1
2015-12   1475071   ¹é¸Þ°¡
2021-04   3748   ²Ù¶ì¿÷
2021-04   2207   Sakura24
2021-04   3132   doping
2021-04   3794   ºÀ·¡
2021-04   2861   ³ª¶ó¶ß
2021-04   4398   ±¼··¼è
2021-04   2506   Àå¿î±â
2021-04   2920   À嵿°Ç2014
2021-04   2961   NUXE
2021-04   2089   ±è¿µ±â
2021-04   2821   ±Þ¿©ÀÏ¿¡¸¸³ª¿ä
2021-04   5280   AMDºô·±
2021-04   3408   Uinx
2021-04   2860   ¸®Ä«¶ó¹Ù
2021-04   2838   ½ÎÀÌÁ¦ÀÌ
2021-04   2632   ¼öÁÝÀº¸Á°í
2021-04   3007   ¾ÈÇü°ï
2021-04   3733   ´ºÀÚ
2021-04   3235   °¡¼ººñ°¡ÁÁ´Ù
2021-04   2704   ÇູÇϼ¼