Skip to content
hakk
  • Home
  • Blog
  • Docs
  • DSA
  • Snippets

Datetime

  • Python date string to date object 2022-10-31

    If you have a date string and need to convert it into a date object, how can it be converted to a date object using Python?

    Python includes within the datetime package a strptime function, here’s an example usage:

    >>> import datetime
    >>> datetime.datetime.strptime('2022-10-30T14:32:41Z', "%Y-%m-%dT%H:%M:%S%z")
    datetime.datetime(2022, 10, 30, 14, 32, 41, tzinfo=datetime.timezone.utc)
    

    Updated code for Windows

    Recently I ran into an issue where a report was generated on Linux but I wanted to process it further on windows. The timezones don’t match up though and will cause issues. Let’s look at how to handle that.

Recent posts
  • How to Update a File's Creation Time in PowerShell
  • How to Run PowerShell Code Only During Certain Times
  • PeopleSoft App Server Freeze Troubleshooting Checklist
  • Build Vim With Python3 Support
  • Understanding the ss Command: A Modern Alternative to netstat
© 2026 hakk
  • Home
  • Blog
  • Docs
  • DSA
  • Snippets