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
10
votes
6 answers

What's the most elegant way to get the end of the day (datetime)?

I'm currently writing some reporting code that allows users to optionally specify a date range. The way it works (simplified), is: A user (optionally) specifies a year. A user (optionally) specifies a month. A user (optionally) specifies a…
rdegges
  • 32,786
  • 20
  • 85
  • 109
10
votes
3 answers

What is the decimal part in timestamp?

I run the following code in python, import time print(time.time()) and the output was: 1557990717.6383634 Can someone explain the two parts to the left and right of the decimal point. Why's there a decimal point?
Joseph
  • 203
  • 1
  • 3
  • 11
10
votes
2 answers

using the timedelta.round() function

I've seen multiple questions asked on how to define your own function that does things similar to this, but I can't figure out how to use timedelta's built in function. Does anyone have an example of a use of timedelta.round()? I have timedelta…
j robertson
  • 141
  • 1
  • 1
  • 6
10
votes
1 answer

Saving a local datetime offset the time by 4 minutes

I'm trying to modify a datetime based on a timezone on save and on load the following way: An input datetime, along with a input timezone are sent to the server and the server should update the datetime to reflect the timezone. So when it saves in…
nobe4
  • 2,802
  • 3
  • 28
  • 54
9
votes
4 answers

Python Plotly How to remove datetime gaps in candle stick chart?

I am trying to remove the datetime gaps in my candlestick (the gaps are the time periods when the stock market is closed, hence there are not data). Can't seem to find a good solution for using plotly graph object. Is there a feasible way to do…
9
votes
1 answer

infer_datetime_format with parse_date taking more time

I was going through pandas documentation. And it quoted that I have a sample csv data…
bigbounty
  • 16,526
  • 5
  • 37
  • 65
9
votes
2 answers

Convert UTC timezone to IST python

The following code line gives me the UTC timing on the production server. timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') Please suggest a way to convert above UTC timezone to IST(Indian Standard Time) timing.
Mahesh
  • 1,117
  • 2
  • 23
  • 42
9
votes
1 answer

Datetime strptime issue with a timezone offset with colons

Currently we are working on an application which is trying to calculate the travel time of a route from a to b, using the 2.db.transport.rest API. Unfortunatly we are receiving timestamps with a timezone offset from that API, such as +01:00. What…
Bruno
  • 91
  • 1
  • 2
9
votes
2 answers

Python Timedelta64 convert days to months

I have a Pandas dataframe with 2 columns representing a start-timestamp and an end-timestamp: start end 2016-06-13 2016-07-20 The datatype of these columns is datetime64[ns]. I now want to create a new column showing the difference in…
beta
  • 5,324
  • 15
  • 57
  • 99
9
votes
6 answers

Python select random date in current year

In Python can you select a random date from a year. e.g. if the year was 2010 a date returned could be 15/06/2010
John
  • 21,047
  • 43
  • 114
  • 155
9
votes
1 answer

datetime: conversion from string with timezone name not working

I have the following string "2017-03-30 08:25:00CET" which I want to convert to a datetime tz-aware object. According this SO question, from python 3.2 it can be done using only datetime module. In addition, from the documentation, I see %z | UTC…
J0ANMM
  • 7,849
  • 10
  • 56
  • 90
9
votes
1 answer

What's the difference between pytz.utc and dt.timezone.utc?

I am writing a library and I don't want to require pytz since the library itself doesn't know or care about timezones (it's reading and writing data in the form of Unix timestamps, which don't have any timezone information associated with them). I…
Kevin
  • 28,963
  • 9
  • 62
  • 81
9
votes
3 answers

What's the best way to store a python timedelta value in mysql?

I need to store an uptime in a mysql environment. The uptime can vary from a few hours to more than one year. I was considering using a DATETIME type for mysql. I'm working with python, and the uptime is obtained from def convertdate(lastrestart): …
asdf
  • 685
  • 7
  • 23
8
votes
1 answer

Python ImportError: sys.meta_path is None, Python is likely shutting down

When using __del__ datetime.date.today() throws ImportError: sys.meta_path is None, Python is likely shutting down import datetime import time import sys class Bug(object): def __init__(self): print_meta_path() def…
8
votes
5 answers

Python: how to compute date ranges from a list of dates?

I have a list of dates, for example: ['2011-02-27', '2011-02-28', '2011-03-01', '2011-04-12', '2011-04-13', '2011-06-08'] How do I find the contiguous date ranges contained within those dates? In the above example, the ranges should…
Continuation
  • 12,722
  • 20
  • 82
  • 106