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

doping   
   Á¶È¸ 3136   Ãßõ 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 2126/5680
2014-05   4944980   Á¤ÀºÁØ1
2015-12   1481675   ¹é¸Þ°¡
2014-03   3184   ¹Â³ë
2016-08   3724   Á¶ÀçÇü3
2016-08   5749   ÀÌÇö±æ
2015-07   3827   ÀÌÁ¾¼Û1
2016-08   3329   ÄĹÚ
2017-08   3654   e5472
08-06   765   Sakura24
2018-11   5975   ´ÃÆĶõ
2021-04   3137   doping
2015-07   6157   À̽½»ç¶û00
2014-03   8936   ±èµ¿¹Î
2016-08   4204   º°¿¡¼­¿Â±×³à
2017-08   3107   ÄÚÄí
2018-11   2160   ±è°Ç¿ì
2022-12   1992   °­Çѱ¸
2015-07   5379   ¾ÈÈ«¿í
2018-11   6456   ¹Ý¼º¸¸
2012-03   5041   ¾Þ±Û·¯
2017-08   5394   Á¤ÀºÁØ1
2021-05   1519   ±èµ¿Çõ1