How to enter date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolindienc
    New Member
    • Aug 2006
    • 48

    #1

    How to enter date

    Hello everyone,
    Since I am very new to programming, I am struggling with this issue. Please show me how to write current date and how to calculate duration time between today's date and previous date.

    Andy
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Here's a tidbit to get you started:
    Code:
    # This module has lots of output formating, but date objects do print
    from datetime import *
    
    dataOjb = date(MINYEAR, 1, 1)
    todaysDate = dataOjb.today()
    print todaysDate
    
    birthDate = date(1963, 1, 28)
    
    print todaysDate - birthDate

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by coolindienc
      Hello everyone,
      Since I am very new to programming, I am struggling with this issue. Please show me how to write current date and how to calculate duration time between today's date and previous date.

      Andy
      Hey, Andy. Since this is your first post in the Python forum, I'd like to welcome you and ask: have you given up on C++ for something just as powerfull, but a lot easier to learn? Just ask me and I'll tell you "good choice".

      Comment

      • coolindienc
        New Member
        • Aug 2006
        • 48

        #4
        Hi bartonc,
        No have not, but this being my first programming course in school, i do not really have a choice. However, I am learning C++ as well. Just wasn't sure how different this language is. So far this seems easier than C++. Thanks for your help.

        Comment

        • coolindienc
          New Member
          • Aug 2006
          • 48

          #5
          however, I was looking to see if I can manually input previous date just as we write in real life.

          Andy

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by coolindienc
            however, I was looking to see if I can manually input previous date just as we write in real life.

            Andy
            This will get ints for passing to other fuctions:

            Code:
            thedate = raw_input("Enter data as mm/dd/yyyy: ")
            month, day, year = (int(val) for val in thedate.split('/'))

            Comment

            Working...