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

doping   
   Á¶È¸ 3144   Ãßõ 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 4597/5682
2015-12   1489175   ¹é¸Þ°¡
2014-05   4952625   Á¤ÀºÁØ1
2014-03   3146   °¡ºü·Î±¸³ª
2015-04   3146   ¾§
2019-11   3146   Ç®·Îµå½Ã½ºÅÛ
2019-12   3146   È£·Õ·Î
2015-01   3146   ÀÜȤÇѸ¶¹ý»ç
2021-03   3146   ÀÌÇö¼®1
2021-04   3145   doping
2015-08   3145   Àü¼³¼ÓÀǹ̡¦
2020-07   3145   auto15151
2015-03   3145   Á¶¾Æ
2020-11   3145   ÇÁ¶û
2018-07   3145   ÁØÄÄ´ö
2019-10   3145   ÄĹÚ
2019-04   3145   1CPUÁöâÈÆ
2017-05   3145   ¹ã±âÂ÷
2017-09   3145   ¸Ó¶óÄ«´Âµ¥
2020-08   3145   LINKINPARK
2019-08   3145   ±è½ÂÇö1
2019-01   3145   ¸®Å°ÆÄ¿ï·¯
2014-03   3144   ±¼´Ù¸®±³