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

RuntimeWarning: DateTimeField received a naive datetime while time zone support is active

Here I am writing a middleware to delete objects older than 3 months. The date_before_2_month and datetime_before_2_months is working fine. I haven't tested yet for filtering But in my console it is giving me a runtime warning saying activity_time…
D_P
  • 802
  • 10
  • 32
0
votes
3 answers

Python pandas dataframe get value from previous row and groupby Months,year

I already a group by done with getting previous row values in a data frame. groupby_result = df.groupby([df['DateAssigned'].dt.strftime('%m').rename('Month')]).agg({'count'}).cumsum().reset_index() The above lines give me a result like this Month …
0
votes
1 answer

Setting up date tick labels from a date ordinal array

I have a 1D array of date ordinals extracted from the datetime module. This array holds the ordinals as floats. I plotted a figure by using matplotlib pyplot as such: import numpy as np from datetime import datetime as dt from matplotlib import…
Madlad
  • 125
  • 12
0
votes
1 answer

List supported date "format codes" for your platform

There is a list of date format codes: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes Is there a way to get a list of supported format codes for your platform? I can't find where format codes are located in source…
Andrius
  • 19,658
  • 37
  • 143
  • 243
0
votes
3 answers

how to add one day in 'yyyy-mm-dd' format in python?

I have this string '2019-01-11', in year-month-day , i want to add one day to this date, and convert it into date format in python. i tried to convert it to date format, so that i can add one day to it by using 'timedelta' class. date_1 =…
0
votes
1 answer

How to compare a date from a list with todays date?

I am trying to compare a list of dates, with the date and time of now. I take this string (just a quick example) from a remote SSH command: Mon Jun 15 16:52:18 2020,Mon Jun 15 16:52:35 2020,Mon Jun 15 16:52:29 2020 ... Date and time of now: now =…
aldegalan
  • 480
  • 2
  • 12
0
votes
0 answers

Index Datetime freq stays NONE after asfreq

I was going through a lot of questions here but nothing is working for me. I try to get an Datetime index for my Pandas Dataframe. tried resample, asfreq. The index is already a Datetime Object, but it keeps the NONE freq. dfz = sale.loc[(sale.Open…
Nadine
  • 1
0
votes
1 answer

Time data does not match format - List of Strings to Date

I have a list of dates (in string format): Mon Jun 15 16:52:18 2020,Mon Jun 15 16:52:35 2020,Mon Jun 15 16:52:29 2020,Mon Jun 15 18:25:30 2020,Mon Jun 15 18:25:14 2020,Mon Jun 15 18:25:50 2020,Mon Jun 15 18:24:47 2020,Mon Jun 15 18:26:04 2020,Sun…
aldegalan
  • 480
  • 2
  • 12
0
votes
2 answers

How can I group dates into pandas

Datos 2015-01-01 58 2015-01-02 42 2015-01-03 41 2015-01-04 13 2015-01-05 6 ... ... 2020-06-18 49 2020-06-19 41 2020-06-20 23 2020-06-21 39 2020-06-22 22 2000 rows × 1 columns I have this df which is made up of a column whose data…
0
votes
3 answers

How to retrieve the date from today excluding weekends with datetime or pandas in Python

I want to create a function that takes in a number and returns the {number} days prior to today, excluding weekends. For example, from datetime import date, timedelta def get_date(days = 5): today = date.today() return today -…
landy
  • 3
  • 1
0
votes
1 answer

Reading and Graphing Dates from a CSV in Python

I have a CSV where the first column is a day and a time and the remaining columns are measurements taken at those times. The dates are in the form "MM/DD/YYYY hh:mm:ss" in a single column. Python reads this as a string. How to I convert this to a…
0
votes
1 answer

How to resolve conflicting of pandas.to_datetime with python's built-in datetime?

Initially I've got print(transactions.Date.loc[0]) >>>30/04/18 First I've done transactions['Date'] = pd.to_datetime(transactions['Date']) Now print(transactions.Date.loc[0]) >>>2018-04-30 00:00:00 After that I check for an equality condition…
Eeshaan
  • 1,557
  • 1
  • 10
  • 22
0
votes
2 answers

Raspberry GPIO, time trigger

I am trying to make a GPIO trigger by time. The first part is just a test, the second part is a WHILE is to trigger the time, I used a IF statement to match the time I wanted. That worked very fine. But inside the While python gives me an error…
0
votes
1 answer

How to convert a datetime from a specific timezone to its UTC version using the django.utils.timezone library?

I am looking for a function from the django.utils.library that would take a datetime from a specified timezone and return its UTC equivalent. Does such a function exist?
Extranomical
  • 385
  • 1
  • 3
  • 13
0
votes
3 answers

How to get all the timezones date in order by python

i create this loop to give all timezones : import datetime import pytz today=datetime.datetime.now(tz=pytz.UTC) for i in pytz.all_timezones: print(today.astimezone(pytz.timezone(i))) but i want to get them in order from -9 to +14