datetime64("now") is undocumented #10003
Copy link
Copy link
Open
Labels
Description
I found out that you can get the current UTC date with np.datetime64("now").
However this isn't documented here and there are a few things about the behaviour that aren't obvious. For instance it seems that the precision cannot be greater than one second:
In [95]: np.datetime64("now", "ms")
Out[95]: numpy.datetime64('2017-11-11T08:10:31.000')
Reactions are currently unavailable
Activity
shoyer commentedon Nov 12, 2017
See here for the underlying C-function:
numpy/numpy/core/src/multiarray/datetime_strings.c
Lines 189 to 219 in 6582813
Note that it also supports the string "today" indicating a local time.
If we're going to document it, we should probably make sure that the functionality makes sense. In the most recent version of datetime64, we aim for compatibility with Python's datetime module (without timezones). So it's a little strange that "now" means UTC rather than local time (see https://docs.python.org/2/library/datetime.html#datetime.datetime.now) Arguably, we should use something different like "utcnow" for UTC.
The precision issue could potentially be improved, possibly by switching to rely on Python's
time.time()rather than our own implementation. For now it would indeed make sense to document the (potentially) limited precision.mohdsanadzakirizvi commentedon Dec 24, 2017
Would like to work on this as my first contribution, is it open ?
shoyer commentedon Dec 24, 2017
As noted above, I think we should probably clean up this functionality before documenting it, which would encourage more people to rely on functionality that would likely change.
gosuto-inzasheru commentedon Feb 9, 2020
Yeah the precision thing is quite misleading I think, passing
'ms'only increases the size of the float.Shreyjaradi commentedon May 20, 2024
I have raised an PR to add the example of
np.datetime64("now", "ms")#26477