views:

68

answers:

4

If the month is: "12" Day is: "05" Year is: "2010"

Can this be converted into a timestamp somehow, in a very simple way?

+1  A: 
import datetime

d = datetime.datetime(year=2010,day=5,month=12)

d
datetime.datetime(2010, 12, 5, 0, 0)
MattH
+2  A: 

You can use the datetime module:

import datetime

d = datetime.date(year, month, day)

At this point, d is a date object.

If you want a timestamp from that, you can do the following:

import time

timestamp = time.mktime(d.timetuple())
TM
A: 
import time

>>> time.mktime((2010,12,5,0,0,0,0,0,0))
1291500000.0
adamk
+1  A: 

In the interest of showing a man how to fish vs giving a man a fish...

A good starting point for these sorts of questions is the Python library documentation. If you look on that page for the word "date" you will easily find the datetime module.

Craig McQueen