timezone

How to calculate current time in different timezone correctly in Python

How to calculate current time in different timezone correctly in Python Question: I was trying to calculate the current time in NYC (EST time aka Eastern Daylight time or GMT+4) given current time in Israel (Israel daylight time, currently GMT+3) where I’m currently located. So right now Israel is 7 hrs ahead of NYC, but …

Total answers: 1

How to extract date from datetime column in polars

How to extract date from datetime column in polars Question: I am trying to move from pandas to polars but I am running into the following issue. import polars as pl df = pl.DataFrame( { "integer": [1, 2, 3], "date": [ "2010-01-31T23:00:00+00:00", "2010-02-01T00:00:00+00:00", "2010-02-01T01:00:00+00:00" ] } ) df = df.with_columns( [ pl.col("date").str.strptime(pl.Datetime, fmt="%Y-%m-%dT%H:%M:%S%z").dt.with_time_zone("Europe/Amsterdam"), ] ) …

Total answers: 2

Calculating timedeltas across daylight saving

Calculating timedeltas across daylight saving Question: I’m facing a python timezones problem and am unsure of what is the right approach to deal with it. I have to calculate timedeltas from given start and end DateTime objects. It can happen that daylight saving time will change during the runtime of my events, so I have …

Total answers: 1

What is the correct way to convert Django date and time fields to current timezone?

What is the correct way to convert Django date and time fields to current timezone? Question: I feel like I’m missing something obvious: I implemented timezones in my Django app using the SO solution here and it seems to be working (i.e. when the user changes to their timezone, Django’s {% get_current_timezone as TIME_ZONE %} …

Total answers: 1

How to convert multiple time zone column to UTC in Python

How to convert multiple time zone column to UTC in Python Question: I have a dataset where the date_time column contains a mixture of BST and GMT date and times, in the following format ‘Sun 27 Mar 2022 12:59:03 AM GMT’. I would like to convert this whole column into the following format ‘2022-03-27 00:59:03’, …

Total answers: 1

Why is python's datetime conversion wrong in one direction?

Why is python's datetime conversion wrong in one direction? Question: I am trying to convert a timezone aware datetime.datetime object to UTC and make it naive. For the conversion, I use the following code: from datetime import datetime import pytz dt: datetime = datetime(2023, 1, 2, 12, 0, 0, tzinfo=pytz.timezone("Europe/Amsterdam")) print(pytz.timezone("Europe/Amsterdam").utcoffset(dt=datetime.now())) print(dt) print(dt.astimezone(pytz.timezone("UTC"))) This outputs …

Total answers: 1

How to convert the datetime while working on a big data?

How to convert the datetime while working on a big data? Question: enter image description hereI’m working on Colab and trying to separate out a test set of the last 2 months of data but I’m facing this error (ValueError: Both dates must have the same UTC offset), I know the error is because the …

Total answers: 3

Python using timedelta around DST hour

Python using timedelta around DST hour Question: I have a script that receives regular pings, and whenever the last ping is more than 10 minutes ago it throws an error and goes into panic mode. Simplified example: from datetime import datetime import time from random import randint class Checker: def __init__(self): self.last_ping = datetime.now() def …

Total answers: 1

How to convert Date to timezone aware datetime in polars

How to convert Date to timezone aware datetime in polars Question: Let’s say I have df = pl.DataFrame({ "date": pl.Series(["2022-01-01", "2022-01-02"]).str.strptime(pl.Date), "%Y-%m-%d") }) How do I localize that to a specific timezone and make it a datetime? I tried: df.select(pl.col(‘date’).cast(pl.Datetime(time_zone=’America/New_York’))) but that gives me shape: (2, 1) date datetime[μs, America/New_York] 2021-12-31 19:00:00 EST 2022-01-01 19:00:00 …

Total answers: 1