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

Calculate business hours between two dates by excluding non business hours in pandas data frame

I have two columns with start time and end time. I want to calculate difference between these two columns and exclude non-business hours. Business hours start on Monday 2:30 AM and ends on Saturday 6:30 AM. Monday and Saturday has different…
0
votes
1 answer

How to repeat django event occurrence period?

I have a model that gets the day and time of week when an event should always occur. Also, the number of days before the event that people will be able to attend. def validate_only_one(obj): model = obj.__class__ if model.objects.count() > 0…
Thales
  • 545
  • 1
  • 6
  • 17
0
votes
1 answer

How to convert a datetime to a date?

I'm designing a class that takes a date argument defaulting to today. I understand datetime.now() gives the current timestamp, but am not able to find a way to convert the datetime instance to date. Obviously I can do date(datetime.now().year,…
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
0
votes
1 answer

pandas.to_datetime issue identifying correct format when using HKMA's Open API

I am trying to identify the appropriate format used in my obtained dataframe, but I am having trouble finding anything that works. The issue is that the format contains yearly figures for which the month is assumed to be some sort of zero-padded…
GACharala
  • 39
  • 8
0
votes
1 answer

Exact mid time interval between two time

I try to get mid time between two time, here is my code which i tried but it didn't work. import datetime import time start_time = datetime.datetime.now().time().strftime('5:00') end_time =…
Sana ullah
  • 21
  • 7
0
votes
1 answer

Converting datetime.date to pandas.core.series.Series in Python?

Problem Statement: (Multiple Linear regression) A digital media company (Netflix, etc.) had launched a show. Initially, the show got a good response, but then witnessed a decline in viewership. The company wants to figure out what went wrong. I want…
0
votes
2 answers

How to convert string '6 dec 2019 9pm' to datetime object?

I used strptime() with format '%d %a %Y %-Ip%' but it's throwing the error stating "-I" is bad directive.
0
votes
1 answer

Changing data types on Pandas DataFrame uploaded from CSV - mainly Object to Datetime

I am working on a data frame uploaded from CSV, I have tried changing the data typed on the CSV file and to save it but it doesn't let me save it for some reason, and therefore when I upload it to Pandas the date and time columns appear as object. I…
user11395824
  • 71
  • 1
  • 7
0
votes
1 answer

Render date for yesterday with a link

I have a workspace where users can add note, they can pick a date I am trying to create 2 links, one for yesterday, one for tomorrow. Right now I am using a calendar and it is fine, but I would like to create 2 quick links that send them to the note…
user11005819
0
votes
0 answers

Convert UTC to CST

I wrote the following function to convert UTC to CST (which is working fine): import datetime def utc_datetime_to_cst_1(dt_now): """ To convert UTC into CST, subtract 6 hours During daylight saving (summer) time, you would only subtract…
briba
  • 2,857
  • 2
  • 31
  • 59
0
votes
2 answers

How to convert list string to timestamp

I have list of US Holidays: Holidays = ["January 01, 2019","January 21, 2019","February 14, 2019","February 18, 2019","April 19, 2019","April 21, 2019","May 12, 2019","May 27, 2019","June 16, 2019","July 04, 2019","September 02, 2019","October 14,…
affadam seven
  • 21
  • 1
  • 3
0
votes
1 answer

Django Overriding DateTimeField

I currently have a form which allows users to select a datetime, which I display using a custom bootstrap date picker. I have the date shown formatted to MM/DD/YYYY hh:mm A. The problem is the field doesn't recognize this format. I subclassed…
Silent Beast
  • 119
  • 2
  • 12
0
votes
2 answers

Data grouping into weekyly, monthly and yearly for large datasets using python?

I have datasets that record 'X' value for the 20 years in Dataframe format. X records the data with 3 hrs average and sample of data are given below. Time_stamp X 1992-01-01 03:00:00 10.2 1992-01-01 06:00:00 10.4 1992-01-01…
Ankita
  • 485
  • 5
  • 18
0
votes
2 answers

Syntax to use to make "minus x days" with Python 3.8?

import pandas as pd import requests from bs4 import BeautifulSoup import time import datetime from datetime import date, timedelta # MM/DD/YYYY : time.strftime("%m/%d/%Y") # YYYYMMDD : time.strftime('%Y%m%d') if…
manny-
  • 129
  • 2
  • 10
0
votes
4 answers

How do I convert string into datetime.datetime object?

I have this date as a string birthday = "2000-01-23 00:00:00" How do I turn it into a datetime.datetime object, so when I print birthday it prints out datetime.datetime(2000, 1, 23, 0, 0) birthday = "2000-01-23 00:00:00" # birthday = datetime…
Jackie
  • 372
  • 5
  • 16
1 2 3
99
100