Date / Month

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • parthpatel
    New Member
    • Apr 2007
    • 14

    #1

    Date / Month

    suppose i have a present date in date format

    now i m passing it as string

    again afterwards i get the date as string

    now i first need to convert it in date format

    than i need to get the same date of the next coming month

    How can i do that?
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #2
    how about giving an example.

    Comment

    • parthpatel
      New Member
      • Apr 2007
      • 14

      #3
      todays date - 2007/ 04/22


      now i want the date exactly after a month how can i get that

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by parthpatel
        todays date - 2007/ 04/22


        now i want the date exactly after a month how can i get that
        >>> from time import strptime
        >>> from datetime import datetime
        >>> aDate = datetime(*strpt ime("2007/04/22", "%Y/%m/%d")[0:6])
        >>> aMonth = timedelta(days= 30)
        >>> (aDate + aMonth).strftim e("%Y/%m/%d")
        '2007/05/22'
        >>>

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by bartonc
          >>> from time import strptime
          >>> from datetime import datetime
          >>> aDate = datetime(*strpt ime("2007/04/22", "%Y/%m/%d")[0:6])
          >>> aMonth = timedelta(days= 30)
          >>> (aDate + aMonth).strftim e("%Y/%m/%d")
          '2007/05/22'
          >>>
          Here is the section of the Python Manual that that came from.

          Comment

          Working...