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
2 answers

Convert string to date using arrow python

I'm trying to convert string to date using arrow module. During the conversion, I received this error: arrow.parser.ParserMatchError: Failed to match '%A %d %B %Y %I:%M:%S %p %Z' when parsing 'Wednesday 06 November 2019 03:05:42 PM CDT' The…
liorko
  • 1,435
  • 2
  • 24
  • 41
0
votes
0 answers

How can I apply the numpy modulus/remainder operation to a list of datetimes?

In Python 3, I have a list of datetime objects that I would like, using numpy, to wrap (python modulus % operator) by dividing by a fixed time period represented as a python timedelta. The goal is to derive a numpy array containing the…
jtlz2
  • 7,700
  • 9
  • 64
  • 114
0
votes
1 answer

Checking if a datetimeindex falls into another list of dates and applying condition

Using python, I've created a dataframe with a datetime index. datetime_index = pd.date_range(start='2018-01-01', end='2019-12-31', freq='D') df = pd.DataFrame({}, index=datetime_index) Now I would like to be able to search through a list of dates,…
fafz
  • 81
  • 7
0
votes
1 answer

Check If one datetime lies between two datetimes python

I am trying to check if one datetime lies between two datetimes, most of the cases return true, but in below case it return false whereas it should return true, how can I check it in proper way. time1=1900-01-01 08:30:00 time2=1900-01-01…
Nabeel Ayub
  • 1,060
  • 3
  • 15
  • 35
0
votes
2 answers

Date Time difference between hour of the day and time now

Time = datetime.datetime.now().time() I wanted to find the difference in seconds between the Time above^ and the hour of the day: for example if the Time = 15:07:25.097519, so the hour of the day is 15:00:00, i want to store 445.097519‬ seconds to…
ictwinner
  • 19
  • 5
0
votes
2 answers

Add hours or minutes(randomly generated) in 24 hour format time python

I have a 24 hour format lets 10:00:00 now I want to randomly generate hours range(1 to 2.5) and add it in a my 24 hour format 10:00:00. e.g random_hour=0.30 // how I can generate time randomly 24_hour_format=24_hour_format+random_hour // result…
Nabeel Ayub
  • 1,060
  • 3
  • 15
  • 35
0
votes
0 answers

Using Openpyxl To Increment A Date In Excel

I'm trying to increment a date using openpyxl. Here's some example code: import openpyxl import os import datetime os.chdir("C:\\Personal\\Rentals\\xxxx") wb = openpyxl.load_workbook(filename = 'Income_Receipts.xlsx', read_only=False) sheet =…
Robt800
  • 29
  • 7
0
votes
2 answers

Is there a more concise way of getting today's date, at a specified time in python

I need a datetime object whose date is today's date, but whose time is specified (3 am). I tried this: dt.now().date() + timedelta(hours=3) -> Can't add timedelta to dt.date object foo = dt.now() foo.hour = 3 foo.minute = 0 foo.second = 0 -> Not…
alex_halford
  • 369
  • 3
  • 10
0
votes
1 answer

How to get the millisecond part while converting to date time from epoch using python

I have a unix epoc time as 1571205166751 I want to convert it to date time in millisecond The desired result should be 2019-10-16 05:52:46:751 AM But using following code I am getting the result as 2019-10-16 05:52:46, not the millisecond…
Kallol
  • 2,089
  • 3
  • 18
  • 33
0
votes
2 answers

Get day name from starting date

I developing a course app. In my app, if a student register for a new course, the teacher must input the starting course date for the student. And in this app, the student can pick up the day that they want to learn to the teacher. e.g: The student…
Tri
  • 2,722
  • 5
  • 36
  • 65
0
votes
1 answer

Looping a function with its input being a url

So I am trying to get into python, and am using other examples that I find online to understand certain functions better. I found a post online that shared a way to check prices on an item through CamelCamelCamel. They had it set to request from a…
0
votes
2 answers

best way to add unpredictable time strings in python3?

a project I'm building takes different time lengths from album tracklists in as strings, and I want to add them up cumulatively. The inputs can vary in unpredictability, such as the following list of input time strings: inputs = ['0:32', '3:19',…
Martin
  • 1,336
  • 4
  • 32
  • 69
0
votes
0 answers

python sum date + days

I have a data frame with a column with number of dates since year 1900. I need to change the format to Y%m%d. For this I created a column datetime.date(1900,1,1) to which try to sum the number of days. I am receiving this error: TypeError:…
0
votes
1 answer

Generate random date of a particular month in order using python

How to Generate random date of a particular month in this particular format.in order wise i.e., from 1 of month to 30 of that month 2011-08-12T20:17:46.384Z Tried this but it generates in regular time date format. This code generates randomly but i…
user11669928
0
votes
1 answer

grab UNIX timestamp down to the last second

How would I grab the exact Unix time in python3? import time t = (time.strftime("%d/%m/%Y")) For example I can use the code above and plug that into a converter. But this does not work for what I need because there is no output to hours and seconds
John Tobey
  • 23
  • 6
1 2 3
99
100