To remove a timezone (tzinfo) from a datetime object:

# dt_tz is a datetime.datetime object
dt = dt_tz.replace(tzinfo=None)

If you are using a library like arrow, then you can remove timezone by simply converting an arrow object to to a datetime object, then doing the same thing as the example above.

# <Arrow [2014-10-09T10:56:09.347444-07:00]>
arrowObj = arrow.get('2014-10-09T10:56:09.347444-07:00')

# datetime.datetime(2014, 10, 9, 10, 56, 9, 347444, tzinfo=tzoffset(None, -25200))
tmpDatetime = arrowObj.datetime

# datetime.datetime(2014, 10, 9, 10, 56, 9, 347444)
tmpDatetime = tmpDatetime.replace(tzinfo=None)

Why would you do this? One example is that mysql does not support timezones with its DATETIME type. So using ORM's like sqlalchemy will simply remove the timezone when you give it a datetime.datetime object to insert into the database. The solution is to convert your datetime.datetime object to UTC (so everything in your database is UTC since it can't specify timezone) then either insert it into the database (where the timezone is removed anyway) or remove it yourself. Also note that you cannot compare datetime.datetime objects where one is timezone aware and another is timezone naive.

##############################################################################
# MySQL example! where MySQL doesn't support timezones with its DATETIME type!
##############################################################################

arrowObj = arrow.get('2014-10-09T10:56:09.347444-07:00')

arrowDt = arrowObj.to("utc").datetime

# inserts datetime.datetime(2014, 10, 9, 17, 56, 9, 347444, tzinfo=tzutc())
insertIntoMysqlDatabase(arrowDt)

# returns datetime.datetime(2014, 10, 9, 17, 56, 9, 347444)
dbDatetimeNoTz = getFromMysqlDatabase()

# cannot compare timzeone aware and timezone naive
dbDatetimeNoTz == arrowDt # False, or TypeError on python versions before 3.3

# compare datetimes that are both aware or both naive work however
dbDatetimeNoTz == arrowDt.replace(tzinfo=None) # True
Answer from user1094786 on Stack Overflow
🌐
Expert Code Blog
expertcodeblog.wordpress.com › 2018 › 12 › 07 › c-remove-utcoffset-from-datetime
C# – Remove UtcOffset from DateTime | Expert Code Blog
December 7, 2018 - DateTime contains UTC format informations. To remove UTC informations we need to create an instance of DateTime using its Ticks property. For example: // DateTime that contains UTC info DateTime date = DateTime.Now; date.ToString("o"); // Output ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › powerquery-m › datetimezone-removezone
DateTimeZone.RemoveZone - PowerQuery M | Microsoft Learn
September 16, 2025 - Access to this page requires authorization. You can try changing directories. ... Returns a #datetime value from dateTimeZone with timezone information removed.
Discussions

c# - Remove Time Zone Offset from DateTimeOffset? - Stack Overflow
I was sure that SpecifyKind would convert my DateTimeOffset. That is, change both the time and the time zone offset. But, my test indicates that this code just changes the time zone offset, which is what I want. Is there a problem with doing it this way? ... You need to think of this a little different. You always have a timezone ... More on stackoverflow.com
🌐 stackoverflow.com
c# - Convert datetime without timezone - Stack Overflow
I have date in string: "2013-07-22T08:51:38.000-07:00" When I try parse this string, I receive date with offset of timezone. How can I make it without timezone offset? ---UPDATE--- it is that I More on stackoverflow.com
🌐 stackoverflow.com
python - Remove timezone information from datetime object - Stack Overflow
The 140645 part isn't timezone info, it's the microseconds value of the datetime object. What are you really trying to do here? ... For those that came here for the actual question 'Remove timezone information from datetime object', the answer would be something like: datetimeObject.replac... More on stackoverflow.com
🌐 stackoverflow.com
November 9, 2018
Removing the time zone from datetime field in QGIS - Geographic Information Systems Stack Exchange
No, I think including timezone is intended, that's not an issue. This format is not primarily intended for visualization - if you want to visualize, best convert to a string. ... After inspecting provided GeoPackage I could not find the problem in any of your datetime fields, specifically ... More on gis.stackexchange.com
🌐 gis.stackexchange.com
December 6, 2021
Top answer
1 of 1
389

To remove a timezone (tzinfo) from a datetime object:

# dt_tz is a datetime.datetime object
dt = dt_tz.replace(tzinfo=None)

If you are using a library like arrow, then you can remove timezone by simply converting an arrow object to to a datetime object, then doing the same thing as the example above.

# <Arrow [2014-10-09T10:56:09.347444-07:00]>
arrowObj = arrow.get('2014-10-09T10:56:09.347444-07:00')

# datetime.datetime(2014, 10, 9, 10, 56, 9, 347444, tzinfo=tzoffset(None, -25200))
tmpDatetime = arrowObj.datetime

# datetime.datetime(2014, 10, 9, 10, 56, 9, 347444)
tmpDatetime = tmpDatetime.replace(tzinfo=None)

Why would you do this? One example is that mysql does not support timezones with its DATETIME type. So using ORM's like sqlalchemy will simply remove the timezone when you give it a datetime.datetime object to insert into the database. The solution is to convert your datetime.datetime object to UTC (so everything in your database is UTC since it can't specify timezone) then either insert it into the database (where the timezone is removed anyway) or remove it yourself. Also note that you cannot compare datetime.datetime objects where one is timezone aware and another is timezone naive.

##############################################################################
# MySQL example! where MySQL doesn't support timezones with its DATETIME type!
##############################################################################

arrowObj = arrow.get('2014-10-09T10:56:09.347444-07:00')

arrowDt = arrowObj.to("utc").datetime

# inserts datetime.datetime(2014, 10, 9, 17, 56, 9, 347444, tzinfo=tzutc())
insertIntoMysqlDatabase(arrowDt)

# returns datetime.datetime(2014, 10, 9, 17, 56, 9, 347444)
dbDatetimeNoTz = getFromMysqlDatabase()

# cannot compare timzeone aware and timezone naive
dbDatetimeNoTz == arrowDt # False, or TypeError on python versions before 3.3

# compare datetimes that are both aware or both naive work however
dbDatetimeNoTz == arrowDt.replace(tzinfo=None) # True
Top answer
1 of 1
30

The issue doesn't have anything to do with the database actually. If you set a breakpoint or log the output somewhere, you should be able to see the offset being tacked on shortly after this code:

CopytestDateAndTime = testDateAndTime.DateTime.Date;

Let's break this down:

  • You started with a DateTimeOffset value of 2008-05-01T08:06:32+01:00
  • You then called .DateTime, which resulted in a DateTime value of 2008-05-01T08:06:32 with DateTimeKind.Unspecified.
  • You then called .Date, which resulted in a DateTime value of 2008-05-01T00:00:00 with DateTimeKind.Unspecified.
  • You assign the result back to testDateAndTime, which is of type DateTimeOffset. This invokes an implicit cast from DateTime to DateTimeOffset - which applies the local time zone. In your case, it would appear the offset for this value in your local time zone is -04:00, so the resulting value is a DateTimeOffset of 2008-05-01T00:00:00-04:00, as you described.

You said:

End goal is just to have a date without time or time zone offset.

Well, there is currently no native C# data type that is just a date without a time. There is a pure Date type in the System.Time package in corefxlab, but that's not quite ready for the typical production application. There's LocalDate in the Noda Time library that you can use today, but you'd still have to convert back to a native type before saving to the database. So in the meantime, the best you can do is:

  • Change your SQL Server to use a date type in the field.
  • In your .NET code, use a DateTime with a time of 00:00:00 and DateTimeKind.Unspecified. You'll have to remember to ignore the time portion (as there are indeed dates without a local midnight in certain time zones).
  • Change your test prop to be a DateTime, not a DateTimeOffset.

In general, while DateTimeOffset fits a large number of scenarios (such as timestamping events), it doesn't fit well for date-only values.

I want the current date, with zero offset.

If you really want this as a DateTimeOffset, you'd do:

CopytestDateAndTime = new DateTimeOffset(testDateAndTime.Date, TimeSpan.Zero);

However, I advise against this. By doing so, you're taking the local date of the original value and asserting that it is in UTC. If the original offset is anything other than zero, that would be a false assertion. It is bound to lead to other errors later, as you're actually talking about a different point in time (with potentially a different date) than the one you created.

Regarding the additional question asked in your edit - Specifying DateTimeKind.Utc changes the behavior of the implicit cast. Instead of using the local time zone, it uses UTC time, which always has an offset of zero. The result is the same as the more explicit form I gave above. I still recommend against this, for the same reasons.

Consider an example of starting with 2016-12-31T22:00:00-04:00. By your approach, you'd save into the database 2016-12-31T00:00:00+00:00. However these are two very different points in time. The first one normalized to UTC would be 2017-01-01T02:00:00+00:00, and the second one converted to the other time zone would be 2016-12-30T20:00:00-04:00. Notice the change of dates in the conversion. This is probably not the behavior you'd want creeping into your application.

🌐
Expert Code Blog
expertcodeblog.wordpress.com › 2018 › 10 › 31 › c-convert-string-to-datetime-ignoring-timezone
C#: how to convert a String to DateTime ignoring TimeZone | Expert Code Blog
October 31, 2018 - DateTime myDt = DateTime.Parse("2018-10-02T11:25:27.860Z"); Now the myDt contains a date with 02/10/2018 13:25:27 value. If we want to ignore the TimeZone, we can use the DateTimeOffset.Parse method:
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-remove-timezone-information-from-datetime-object-in-python
How to remove timezone information from DateTime object in Python - GeeksforGeeks
December 9, 2021 - The DateTime object with timezone information is then manipulated using the .replace() method to remove the timezone information using the tzinfo parameter. ... from datetime import datetime, timezone # Get the datetime object using datetime ...
🌐
Python
docs.python.org › 2.4 › lib › datetime-datetime.html
6.10.4 datetime Objects
October 18, 2006 - If you merely want to attach a time zone object tz to a datetime dt without adjustment of date and time members, use dt.replace(tzinfo=tz). If you merely want to remove the time zone object from an aware datetime dt without conversion of date and time members, use dt.replace(tzinfo=None).
🌐
GitHub
github.com › softhints › Pandas-Tutorials › blob › master › datetime › remove-timezone-datetime-column-pandas.ipynb
Pandas-Tutorials/datetime/remove-timezone-datetime-column-pandas.ipynb at master · softhints/Pandas-Tutorials
" datetime.datetime(2021, 8, 3, 12, 29, 59, 123512, tzinfo=pytz.timezone('US/Pacific')), \n", ... "pyperclip.copy((df.head().to_html(classes='table table-striped text-center', justify='center', index=False)))\n"
Author   softhints
🌐
Appian Community
community.appian.com › discussions › f › general › 14142 › how-to-remove-gmt-5-30-format-from-specific-date-time
How to remove GMT+5:30 format from specific date time?
January 11, 2019 - Hi All, I am facing an issue when I'm trying to add hours to the specific time using caladdhours() function. But by defalut it is adding GMT+5:30 to my time.
🌐
Reddit
reddit.com › r/learnpython › need help removing time zone from datetime
r/learnpython on Reddit: Need help removing time zone from datetime
February 28, 2024 -

So i have a script that pulls some stuff from Sharepoint. One of the fields is the timestamp that an entry was made into the Sharepoint list. When pulling it from the API it is returned in the following format:

ENTERED_TM
2024-02-28T17:48:43Z

The datatype of this field when returned from the API is Object. I want to drop the time zone stuff so i just have YYYY-MM-DD H:M:S.

I've tried a couple different things:

First I convert it to datetime with cleaned_df["ENTERED_TM"] = pd.to_datetime(cleaned_df["ENTERED_TM"])

Then i've tried 2 ways of dropping the time zone cleaned_df["ENTERED_TM"].dt.tz_convert(None) and cleaned_df["ENTERED_TM"].dt.tz_localize(None)

Both of those leave me this:

ENTERED_TM
2024-02-28 17:48:43+00:00

Any help would be appreciated

🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.dt.tz_convert.html
pandas.Series.dt.tz_convert — pandas 3.0.2 documentation
With the tz=None, we can remove the timezone (after converting to UTC if necessary): >>> dti = pd.date_range( ... start="2014-08-01 09:00", freq="h", periods=3, tz="Europe/Berlin" ... ) >>> dti DatetimeIndex(['2014-08-01 09:00:00+02:00', '2014-08-01 10:00:00+02:00', '2014-08-01 11:00:00+02:00'], ...
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DatetimeIndex.tz_convert.html
pandas.DatetimeIndex.tz_convert — pandas 3.0.1 documentation
With the tz=None, we can remove the timezone (after converting to UTC if necessary): >>> dti = pd.date_range( ... start="2014-08-01 09:00", freq="h", periods=3, tz="Europe/Berlin" ... ) >>> dti DatetimeIndex(['2014-08-01 09:00:00+02:00', '2014-08-01 10:00:00+02:00', '2014-08-01 11:00:00+02:00'], ...
🌐
ExifTool
exiftool.org › forum › index.php
how to remove the time zone information?
Due to high forum load from overly aggressive AI bots, only registered members are currently allowed access. Please login below or sign up for an account with ExifTool Forum Log in Username: Password: Time to stay logged in: Forever 1 Hour 1 Day 1 Week 1 Month · Forgot your password