Python Forum
Confusion with datetime 'dst' function result
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confusion with datetime 'dst' function result
#1
I have found the result of the datetime 'dst' funtion to be confusing. If I create a datetime object this way:

import datetime, pytz
myDate = datetime.datetime.now(tz=pytz.timezone("US/Eastern"))

and then type

print(myDate.timetuple().tm_isdt)

I get a '0', which correctly means that my date/time is not during daylight saving time. But then I create a new date with

newDate = myDate - datetime.timedelta(days=180)

which gives me a date/time on May 19, 2019. But if I type

print(newDate.timetuple().tm_isdt)

I still get a '0' even though my new date is during daylight saving time. Or, more practically, the statement

print(myDate.dst() == newDate.dst())

results in 'True' even though one date was during daylight saving time and the other wasn't. Is there a way to avoid this confusion (other than limiting any usage of the 'dst' function to the line immediately after a datetime object is created)?
Reply


Messages In This Thread
Confusion with datetime 'dst' function result - by jsmith1703 - Nov-15-2019, 06:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to use result of solver in another function ross1993hall 0 1,430 Aug-10-2020, 10:29 AM
Last Post: ross1993hall
  Pass integers to datetime.date function florian 3 2,767 Jul-18-2020, 04:43 AM
Last Post: scidam
  How to use function result in another function Ayckinn 4 2,870 Jun-16-2020, 04:50 PM
Last Post: Ayckinn
  Pandas's regular expression function result is so strange cools0607 6 3,262 Jun-15-2020, 07:34 AM
Last Post: cools0607
  TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 'str' findbikash 2 9,687 Sep-18-2019, 08:32 AM
Last Post: buran
  readshapefile function in basemap - confusion regarding arguments sendiptangshu 1 2,571 Mar-09-2019, 09:29 AM
Last Post: Larz60+
  Erratic Datetime result timsch 0 2,053 Dec-27-2018, 01:49 AM
Last Post: timsch
  SQLAlchemy DateTime result 0's AMarotta97 0 2,292 Oct-01-2018, 04:35 AM
Last Post: AMarotta97
  Why the IDE cannot show the result of zip function? Tony 2 2,947 May-19-2018, 02:58 AM
Last Post: Tony
  confusion on print function volcano 3 3,686 Mar-11-2018, 10:41 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020