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
6 years agoorry, this simply discards timezone info, it doesn't incorporate it into the time. However, I have found the solution with a python script.
Macc-PA
Helper I
5 years agoHi, Can you share the steps you used to add the timestamp to the date using python
- h4tt3n5 years ago
Helper V
Macc-PA I think this is the script. After all, it's one year ago, and we ended up not using it anyway.
import pytzimport datetimetz = pytz.timezone('Europe/Copenhagen')dt = datetime.datetime.utcnow()offset_seconds = tz.utcoffset(dt).secondsoffset_hours = offset_seconds / 3600.0#print ("{:+d}:{:02d}".format(int(offset_hours), int((offset_hours % 1) * 60)))print( offset_hours )- Macc-PA5 years ago
Helper I
Thanks 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.