Python - how to get a python datetime from a sql DateTime
moody31415
Posts: 8
I'm trying to generate data from a previous column - basically I want to figure out "week starting" (eg, value is always a Monday) given a datetime column.
What I'd like to do is treat the SQL DateTime column as a python datetime (https://docs.python.org/2/library/datet ... me-objects), which would allow me to do this in a python script:
foo = otherColumn
dayOfWeek = foo.date().weekday()
return foo.date().AddDays(-dayOfWeek)
Of course, python doesn't have an AddDays, but I could use timedelta if necessary.
How do I convert a sql DateTime to a python datetime?
Thanks!
What I'd like to do is treat the SQL DateTime column as a python datetime (https://docs.python.org/2/library/datet ... me-objects), which would allow me to do this in a python script:
foo = otherColumn
dayOfWeek = foo.date().weekday()
return foo.date().AddDays(-dayOfWeek)
Of course, python doesn't have an AddDays, but I could use timedelta if necessary.
How do I convert a sql DateTime to a python datetime?
Thanks!
Comments
I think you'll find what you're looking for here:
http://stackoverflow.com/questions/1429 ... -timestamp
Kind Regards,
Nick
Redgate Support