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

doping   
   Á¶È¸ 3138   Ãßõ 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
2015-12   1483668   ¹é¸Þ°¡
2014-05   4947017   Á¤ÀºÁØ1
2019-06   2524   AKMU
2019-12   2524   ¸Ó¶óÄ«´Âµ¥
2021-04   2524   ÁÒ½´¾Æ
2020-12   2524   ¸¶½ºÄÚÆ®
2020-05   2524   öÀÌ´Ô
2019-12   2524   °Ü¿ï³ª¹«
2019-12   2525   Ȧ¸¯0o0
2019-09   2525   Nikon
2022-06   2525   ¹¹Áö¹¹¾ß
2019-11   2525   ¼ÛÁö¸¸
2020-03   2525   ÇϾá¾Æºü
2018-11   2525   ¹ü¹üÀÌ
2021-05   2525   ¿øȭä±¼
2019-01   2525   °£Àå°ÔÀå
2020-09   2525   ´Þ¸®´Â¾î¹¬¹Ù
2019-08   2525   Àü»êÁ÷µù
2021-03   2525   Sikieiki
2019-08   2525   ±è°Ç¿ì
2019-08   2525   newretrowave
2020-04   2525   ±â¶ó¿þÀÌ