How to create a date in Python?

Date objects can be created using the datetime.date() method. This method takes year, month and day parameters.

import datetime
 
# Create 7th Feb 2011
d = datetime.date(2011,2,7)
 
assert str(d) == '2011-02-07'
You can leave a response, or trackback from your own site.

One Response to “How to create a date in Python?”

  1. Rusty Shack says:

    Next step: show how to format it, if CCYY-MM-DD format is not desired.

Leave a Reply