Questions tagged [python-datetime]

Python's built-in datetime module provides classes for manipulating dates and times in both simple and complex ways.

Python's built-in datetime module provides classes for manipulating dates and times in both simple and complex ways.

View on Python docs - for Python 2 and Python 3.

1880 questions
0
votes
1 answer

Pandas: insert a new row in pandas dataframe to populate with dates

My excel file has following data: I would like to populate a new row with dates for that particular month starting from first Monday of that month. Example: For May 2020 it should be as follows: The dates are in d/m/yyyy format. Is there any way…
RSM
  • 645
  • 10
  • 25
0
votes
2 answers

python time stamp convert to datetime without a year specified

I have a csv file of a years worth of time series data where the time stamp looks like the code insert below. One thing to mention about the data its a 30 year averaged hourly weather data, so there isnt a year specified with the time…
bbartling
  • 3,288
  • 9
  • 43
  • 88
0
votes
1 answer

How to get standard datetime from tweet.create_at

I am implementing tweepy api in my project and I am trying to get the time a tweet was created using tweet.created_at . It returns a set of Number instead of the actual date string that is shown in the Official twitter API docs. below is the code to…
0
votes
2 answers

How to remove milliseconds in datetime python?

I want to print the amount of days, hours, minutes and seconds until christmas day but when it prints, it also gives me the millisecond. I tried doing print(remain_until_xmas.strip(.) but that didn't work. Here is the code import datetime as…
AyeAreEm
  • 353
  • 6
  • 14
0
votes
2 answers

Unable to convert a string to a datetime object in python and perform some time related calculations with it

What I am trying to do is to get the current datetime of a place using an API with python and extract datetime from it. The code that I have is: import requests import json from datetime import datetime import time def get_current_time_from_api(): …
0
votes
0 answers

converting a string with microseconds to a datetime object with python

I'm trying to convert a datetime string to a datetime object. The datetime string looks like this: 2020-05-04 2004:33:39.654942 I tried using datetime.datetime.strptime method by implementing: datetime.datetime.strptime("2020-05-04…
sandrosil
  • 543
  • 3
  • 9
  • 21
0
votes
1 answer

Transform a long format date to a short format

The small program I am using (below) gives a Date0 value in a "long" form: import pandas as pd from datetime import datetime, timedelta df = pd.DataFrame( [ ["A", -33.415424] ], columns = [ …
Andrew
  • 926
  • 2
  • 17
  • 24
0
votes
2 answers

Datetime arithmetics with day periods

Given a TZ-aware datetime, I want to find the datetime of the same time on the previous day in the same timezone (not necessarily same offset). I came up with the solution below. tz = pytz.timezone("Europe/Paris") myDatetime =…
Philipp
  • 4,659
  • 9
  • 48
  • 69
0
votes
1 answer

AttributeError: 'str' object has no attribute 'date'

I have written code as below: import datetime as dt d = dt.date(2000, 1, 15) But I am getting an error: AttributeError Traceback (most recent call last) in 1 # for loop - to…
0
votes
1 answer

How to number timestamps that comes under particular duration of time in dataframe

If we can divide time of a day from 00:00:00 hrs to 23:59:00 into 15 min blocks we will have 96 blocks. we can number them from 0 to 95. I want to add a "timeblock" column to the dataframe, where i can number each row with a timeblock number that…
reddi hari
  • 173
  • 1
  • 12
0
votes
3 answers

Checking for equality of multiple fields of two datetime objects

I want to make sure two datetime objects have the same date and time up to the seconds. from datetime import datetime time_a = datetime(2020, 4, 29, 3, 14, 15, 9) time_b = datetime(2020, 4, 29, 3, 14, 15, 10) I can't just do assert time_a ==…
Vermillion
  • 1,238
  • 1
  • 14
  • 29
0
votes
1 answer

What is the best method of creating datetime object from existing timestamp in python?

I have a sensor that sends a data along with timestamp as a string which is parsed by a python script. The timestamp is then stored in it's own variable that is already formatted in hh:mm:ss like this for example: 23:52:50 What I want to do is…
0
votes
2 answers

In dataframe add time offset column to another datetime column

I have a dataframe with the following infos: Departure Time Offset Dep Arrival Time Offset Arr 0 05:10 +01:00 08:25 +01:00 1 08:05 +01:00 10:10 +01:00 2 …
Huebschi
  • 59
  • 6
0
votes
1 answer

Calculate time difference between times with time offset column

I have a dataframe with the following infos: Departure Time Offset Dep Arrival Time Offset Arr 0 07:10 +01:00 08:25 +01:00 1 09:05 +01:00 10:10 +01:00 2 …
Huebschi
  • 59
  • 6