strftime

how to handle timestamps from summer and winter when converting strings in polars

how to handle timestamps from summer and winter when converting strings in polars Question: I’m trying to convert string timestamps to polars datetime from the timestamps my camera puts in it RAW file metadata, but polars throws this error when I have timestamps from both summer time and winter time. ComputeError: Different timezones found during …

Total answers: 2

How can I print a day and a time using Python strftime?

How can I print a day and a time using Python strftime? Question: how can I print a day and a time using Python strftime? My code is below, but any time I run it, I get "ValueError: time data ‘1 day, 2:45:00’ does not match format ‘%H:%M:%S’" . I want the output to be …

Total answers: 1

pd.to_datetime doesn't work on values similar to '10/30/2022 7:00:00 AM +01:00'

pd.to_datetime doesn't work on values similar to '10/30/2022 7:00:00 AM +01:00' Question: I have a pandas dataframe with the following column: import pandas as pd df = pd.DataFrame([’10/30/2022 7:00:00 AM +01:00′, ’10/31/2022 12:00:00 AM +01:00′, ’10/30/2022 3:00:00 PM +01:00′, ’10/30/2022 9:00:00 PM +01:00′, ’10/30/2022 5:00:00 PM +01:00′, ’10/30/2022 10:00:00 PM +01:00′, ’10/30/2022 3:00:00 AM +01:00′, …

Total answers: 2

Converting datetime format maintaining the datetime data type in python

Converting datetime format maintaining the datetime data type in python Question: I need datetime object in the format mm/dd/yyyy. I tried using strptime: datetime.strptime("05-08-2022","%d-%m-%Y") >>datetime.datetime(2022, 8, 5, 0, 0) That changes the format to YYYY/MM/DD. I know we can change the format using strftime to convert datetime to any format but that results into a …

Total answers: 1

Unexpected strftime() behaviour on Python and macOS

Unexpected strftime() behaviour on Python and macOS Question: I’m obtaining inconsistent behaviour with the output of datetime.strftime(). I’m using macOS Sierra 10.12.6 and Python 3.6.2. I have a Python program, named wut.py, that is #!/usr/bin/python from datetime import datetime import locale if __name__ == “__main__”: print(locale.getlocale()) print(datetime.today().strftime(‘%c’)) In a terminal, I write $ date Gio …

Total answers: 3

How to change the datetime format in Pandas

How to change the datetime format in Pandas Question: My dataframe has a DOB column (example format 1/1/2016) which by default gets converted to Pandas dtype ‘object’. Converting this to date format with df[‘DOB’] = pd.to_datetime(df[‘DOB’]), the date gets converted to: 2016-01-26 and its dtype is: datetime64[ns]. Now I want to convert this date format …

Total answers: 8

What exactly does the T and Z mean in timestamp?

What exactly does the T and Z mean in timestamp? Question: I have this timestamp value being return by a web service “2014-09-12T19:34:29Z” I know that it means timezone, but what exactly does it mean? And I am trying to mock this web service, so is there a way to generate this timestamp using strftime …

Total answers: 1

Why does "%-d", or "%-e" remove the leading space or zero?

Why does "%-d", or "%-e" remove the leading space or zero? Question: On SO question 904928 (Python strftime – date without leading 0?) Ryan answered: Actually I had the same problem and I realised that, if you add a hyphen between the % and the letter, you can remove the leading zero. For example %Y/%-m/%-d. …

Total answers: 1

How do I strftime a date object in a different locale?

How do I strftime a date object in a different locale? Question: I have a date object in python and I need to generate a time stamp in the C locale for a legacy system, using the %a (weekday) and %b (month) codes. However I do not wish to change the application’s locale, since other …

Total answers: 3