Arrow is a Python library that offers a sensible, human-friendly approach to creating, manipulating, formatting and converting dates, times, and timestamps. It implements and updates the datetime type, plugging gaps in functionality, and provides an intelligent module API that supports many common creation scenarios.
Questions tagged [arrow-python]
26 questions
17
votes
1 answer
Difference between timestamps in Arrow
How would I get Arrow to return the difference in hours between two timestamps?
Here's what I have:
difference = arrow.now() - arrow.get(p.create_time())
print(difference.hour)
p.create_time() being the timestamp of the create time of a currently…

Sweepyoface
- 173
- 1
- 2
- 5
16
votes
5 answers
Validate an ISO-8601 datetime string in Python?
I want to write a function that takes a string and returns True if it is a valid ISO-8601 datetime--precise to microseconds, including a timezone offset--False otherwise.
I have found other questions that provide different ways of parsing datetime…

Stew
- 4,495
- 6
- 31
- 41
13
votes
4 answers
Python 3 How to format to yyyy-mm-ddThh:mm:ssZ
I'm new to Python and I cannot for the life of me find my specific answer online. I need to format a timestamp to this exact format to include 'T', 'Z' and no sub or miliseconds like this yyyy-mm-ddThh:mm:ssZ i.e. 2019-03-06T11:22:00Z. There's lots…

ra67052
- 449
- 2
- 4
- 15
12
votes
4 answers
Parse date and time from string with time zone using Arrow
I have
import arrow
s = '2015/12/1 19:00:00'
tz = 'Asia/Hong_Kong'
How can I parse this with Arrow such that I get an Arrow object with the time zone tz? The following defaults to UTC time.
In [30]: arrow.get(s, 'YYYY/M/D HH:mm:ss')
Out[30]:…

mchangun
- 9,814
- 18
- 71
- 101
7
votes
3 answers
How to increment a date using Arrow?
I'm using the arrow module to handle datetime objects in Python. If I get current time like this:
now = arrow.now()
...how do I increment it by one day?

serverpunk
- 10,665
- 15
- 61
- 95
6
votes
4 answers
How to use Arrow type in FastAPI response schema?
I want to use Arrow type in FastAPI response because I am using it already in SQLAlchemy model (thanks to sqlalchemy_utils).
I prepared a small self-contained example with a minimal FastAPI app. I expect that this app return product1 data from…

Karol Zlot
- 2,887
- 2
- 20
- 37
4
votes
1 answer
Getting previous day datetime from arrow
I can get current datetime from arrow like this:
arrow.utcnow().date()
or
arrow.get('2017-02-01').date()
How can I get the previous day datetime? This does not work:
arrow.utcnow().date() - 1
or
arrow.get('2017-02-01').date() - 1

user308827
- 21,227
- 87
- 254
- 417
4
votes
3 answers
Python convert datetime.time to arrow
I need to convert a python object datetime.time to an arrow object.
y = datetime.time()
>>> y
datetime.time(0, 0)
>>> arrow.get(y)
TypeError: Can't parse single argument type of ''

Alejandro Veintimilla
- 10,743
- 23
- 91
- 180
3
votes
1 answer
Convert humanize time into UTC time using arrow python
I have time given in the following format.
'August 28, 2017 Mon 03:30 am - 04:00 am'
I would like to convert it to the following utc format using arrow.
time =[u'2017-08-28T03:30:00+00:00', u'2017-08-28T04:00:00+00:00']
I was able to do it with…

Parshuram Thorat
- 101
- 1
- 2
- 13
2
votes
1 answer
Increment date with arrow in python not changing properties
I am using .replace and .shift method to increment/decrement an arrow date. However the behaviour is completely unexpected. See the python session below as example.
>>> import arrow
>>> ref = arrow.get('2019-08-01', 'YYYY-MM-DD')
>>>…

Noel
- 3,749
- 3
- 22
- 21
2
votes
2 answers
Why is arrow.now() not in a range containing today's day?
I am testing the ability, in arrow, to check whether a date is in a range of dates:
>>> arrow.get('06/09/2017', 'DD/MM/YYYY') in arrow.Arrow.range('day', arrow.get('06/09/2017', 'DD/MM/YYYY'), arrow.get('06/07/2018', 'DD/MM/YYYY'))
True
>>>…

WoJ
- 27,165
- 48
- 180
- 345
2
votes
1 answer
parsing dates in the form of strings using arrow date manipulating python library
I am looking to convert the string "september 20 2010" to a python datetime.date object using arrow.
I have written functions to replace portions of the text and ended up with 9/20/2016 but I want YYYY-MM-DD format and can't seem to get arrow to…

yoshiserry
- 20,175
- 35
- 77
- 104
1
vote
0 answers
get a list of date string between two date string in python(arrow)
Basically, I have two date string and want to get a list of date string between them.
For example, input strings:
start_date = '20180427', end_date = '201800501'
result:
['20180427', '20180428', '20180429', '20180430', '20180501']
I would prefer…

Zihao Zhao
- 439
- 5
- 9
1
vote
2 answers
Timestamp with utc and any other timezone is coming out to be same with arrow
import arrow
print arrow.utcnow()
print arrow.utcnow().timestamp
print arrow.utcnow().to('Asia/Kolkata')
print arrow.utcnow().to('Asia/Kolkata').timestamp
I need the timestamp (in int) of 'Asia/Kolkata' timezone, which is +5:30 from utc.…

Kshitij Mittal
- 2,698
- 3
- 25
- 40
1
vote
1 answer
How to extend arrow? (and similar classes in modules)
I am trying to extend arrow and fail to understand how I can replicate the functionality of the base classes. This is probably due to a lack of clear understanding on how to extend classes in modules (emphasized by my arrow case - this is to say…

WoJ
- 27,165
- 48
- 180
- 345