- 1). Open the IDLE text editor that comes with the Python download. The IDLE text editor is found in Program Files (or Applications for Macintosh), in the Python directory. A blank source code file opens in the IDLE text editor window.
- 2). Import the "time" and "date" modules by writing the following at the top of the source code file:
import time
from datetime import datetime - 3). Create three integer data types that store a year, a month and a day of the month. For example, you can write the following statements below the import statements:
intYear = 2000
intMonth = 11
intDay = 19 - 4). Create a "datetime" object by passing the three integers in as inputs. Write the following statement to create the "datetime" using integers:
d = datetime(intYear, intMonth, intDay) - 5). Print the value of the "datetime" to the output window by writing the following statement:
print(d) - 6). Execute the program by pressing the "F5" key. The program output looks like this:
2000-11-19 00:00:00
SHARE