Return to Snippet

Revision: 51779
at October 5, 2011 00:45 by denakitan


Updated Code
import datetime

if __name__ == '__main__':
    
    # printing today's date formatted as dd/mm/yyyy. For more formatting options, search for strftime() in Python documentation
    print(datetime.date.today().strftime('%d/%m/%Y'))
    
    # creating a date object
    miyazakiBirthDate = datetime.date(1941, 1, 5)
    
    print(miyazakiBirthDate.strftime('%d/%m/%Y'))
    
    # example of date arithmetic operation. Adding one day to miyazakiBirthDate
    miyazakiBirthNextDay = miyazakiBirthDate + datetime.timedelta(days=1)
        
    print(miyazakiBirthNextDay.strftime('%d/%m/%Y'))
    
    # example of date part replacement. Changing the miyazakiBirthDate year to year + 1
    miyazakiFirstBirthday = miyazakiBirthDate.replace(year=miyazakiBirthDate.year + 1)
    
    print(miyazakiFirstBirthday.strftime('%d/%m/%Y'))

Revision: 51778
at October 4, 2011 04:39 by denakitan


Initial Code
import datetime

if __name__ == '__main__':
    
    # printing today's date formatted as dd/mm/yyyy. For more formatting options, search for strftime() in Python documentation
    print datetime.date.today().strftime('%d/%m/%Y')
    
    # creating a date object
    miyazakiBirthDate = datetime.date(1941, 1, 5)
    
    print miyazakiBirthDate.strftime('%d/%m/%Y')
    
    # example of date arithmetic operation. Adding one day to miyazakiBirthDate
    miyazakiBirthNextDay = miyazakiBirthDate + datetime.timedelta(days=1)
        
    print miyazakiBirthNextDay.strftime('%d/%m/%Y')
    
    # example of date part replacement. Changing the miyazakiBirthDate year to year + 1
    miyazakiFirstBirthday = miyazakiBirthDate.replace(year=miyazakiBirthDate.year + 1)
    
    print miyazakiFirstBirthday.strftime('%d/%m/%Y')

Initial URL

                                

Initial Description
Reference of simple operations with dates, such as formatting and arithmetic.

Initial Title
Python - Date - Basics

Initial Tags
date, format, python

Initial Language
Python