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

Pandas: Return part of the day from datetime column directly

Hi all is it possible to get part of the day (morning, noon, afternoon, ...) directly from datetime column in a dataframe using Pandas? For example for day of the week it's possible to do: df['weekday']= df.date.dt.day_name() and it returns:…
0
votes
1 answer

datetime.datetime has no attribute "datetime"

I'm trying to determine if the current time is before or after a specified date using this code: from datetime import datetime def presidentvoting(self): electiondate = datetime.datetime(2020, 1, 31, 0, 0) current_time = datetime.now() …
0
votes
2 answers

How can I convert hour of day and minute of hour to a datetime?

I have a full year of data every minute: dayofyear hourofday minuteofhour 1 0 0 . . 365 23 57 365 23 58 365 23 59 I converted the dayofyear to a…
maximusdooku
  • 5,242
  • 10
  • 54
  • 94
0
votes
2 answers

What's the best way to increment time?

I want to add time given by user to another time and increment it for n number of times start_time = '7:00' #these values will be taken as string by user hour_time = '0:30' increment_var = 5 time_var = datetime.strptime(start_time,…
udaykls
  • 39
  • 7
0
votes
2 answers

how to apply condition in datetime generated from date_range function?

I have function which is generating a time stamp of 10 days at interval of 15mins. These values are stored in a numpy array. I want to apply a condition on each that checks when the time is between 6am and 7pm then print "something" and when its…
Vesper
  • 795
  • 1
  • 9
  • 21
0
votes
1 answer

How to import date from excel and use it?

I have a input file which contain three columns: "start date", "end date" and "interval". Input file: start date end date interval 01/01/2020 10/01/2020 15 i want to use these values in pandas date_range function. my import pandas as…
Vesper
  • 795
  • 1
  • 9
  • 21
0
votes
0 answers

Changing Times into Standard Datetime Format

I'm currently working with a dataset which has a Time variable, however, the times are stored rather oddly. They are stored like: 42:49.0 42:49.0 42:49.1 42:49.1 42:49.2 42:49.2 42:49.3 42:49.3 ... ... 42:49.9 42:49.9 42:50.0 42:50.0 The times are…
0
votes
1 answer

Converting tz naive datetime to tz aware jumps from 0 minutes to 58

When I'm converting unaware datetime to aware, it does a weird thing. It adds 58 minutes. _datetime = datetime.combine(_date,_time) print(_datetime) datetime_tz = _datetime.replace(tzinfo='Europe/Bratislava') print(_datetime_tz) 2020-02-02…
Milano
  • 18,048
  • 37
  • 153
  • 353
0
votes
1 answer

Date converstion using strptime skips UTC part

I am trying to convert string variable to date object the output doesnt have the UTC component. Here is the sample code .. Appreciate your help! import datetime data="2016-01-19T00:00:00.000-0800" result2 =…
0
votes
1 answer

Python's datetime working in specific hour range

I have a executor that executes phone calles according to what user specifies. I want to schedule time only in specific range of hours during the day, for example from 8AM to 6PM. The executor is working 24 hours per day and is checking records in…
Marek
  • 1,189
  • 3
  • 13
  • 33
0
votes
1 answer

Find latest date value in a dictionary

I have this code that requests the information of the stock MSFT (Microsoft), the request goes right and i get all the data i need on it, however it i want to get the latest stock price (in python it sorts it out latest to oldest however i do not…
beepbeep-boop
  • 204
  • 1
  • 2
  • 11
0
votes
1 answer

Unable to pickle datetime subclass

I am trying to pickle and unpickle datetime.datetime subclass object. However, it always yields error and I have no clue why it is and how to solve it. Here is the minimum example: from datetime import datetime, date, time class A(datetime): …
bilibili
  • 33
  • 4
0
votes
1 answer

Handling schedule in Python

I'm developing a function that binds multiple dates, but it doesn't work. import datetime prev_schdl = None schdl_start_date = None schdl_end_date = None schdls = [(2019, 1, 1, 'aa'), (2019, 1, 5, 'vacation'), (2019, 1, 6, 'vacation'), (2019, 1, 7,…
hgseo
  • 25
  • 2
0
votes
1 answer

issue with datetime.strptime python

This is my code: import datetime t1 = "Fri 11 Feb 2078 00:05:21" t2 = "Mon 29 Dec 2064 03:33:48" t3 = "Sat 02 May 2015 19:54:36" t3_time = datetime.datetime.strptime(t3,"%a %d %B %Y %H:%M:%S") print("debug") t2_time =…
Aditya
  • 113
  • 1
  • 7
0
votes
1 answer

Subtracting datetime, one column from another. Getting error: unsupported operand type(s) for -: 'str' and 'str'

Jupyter Notebook Python 3.7 Subtracting datetime one column from another df['dropoff_datetime'] df['pickup_datetime'] Getting error: unsupported operand types(s) for - 'str' and 'str' HELP! Code: import numpy as np df['trip_minutes'] =…
2tan2ten
  • 109
  • 1
  • 9