Forum Discussion
h4tt3n
Helper V
6 years agoConvert a columns of datatype datetimezone to datetime
Hello, I have a table with timestamped data of datatype datetimezone, eg. 07-08-2020 08:00:00 + 02:00. How do I convert this to datetime in a way that takes tz info into account, eg. 07-08-2020...
h4tt3n
Helper V
5 years agoMacc-PA I think this is the script. After all, it's one year ago, and we ended up not using it anyway.
import pytz
import datetime
tz = pytz.timezone('Europe/Copenhagen')
dt = datetime.datetime.utcnow()
offset_seconds = tz.utcoffset(dt).seconds
offset_hours = offset_seconds / 3600.0
#print ("{:+d}:{:02d}".format(int(offset_hours), int((offset_hours % 1) * 60)))
print( offset_hours )
Macc-PA
Helper I
5 years agoThanks for that - in the end we didnt need to use it.
The problem was solved by ensuring our odata datasource was sending the datetime as UTC, ie not converting it to local time.
Once that happened, converting the column to DataTime applied the UTC offset as expected even for datetimes where daylight saving was involved.