Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 882 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a datetime ± infinity?

#1
For floats we have special objects like -inf (and +inf), and which are guaranteed to compare less than (and greater than) other numbers.

I need something similar for datetimes, is there any such thing? In-db ordering must work correctly with django queryset filters, and ideally it should be db-agnostic (but at the very least it must work with mysql and sqlite) and timezone-agnostic.

At the moment I'm using null/`None`, but it is creating very messy queries because `None` is doing the job of *both* -inf and +inf and I have to explicitly account for all those cases in the queries.
Reply

#2
There isn't; the best you have is the [`datetime.datetime.min`](

[To see links please register here]

) and [`datetime.datetime.max`](

[To see links please register here]

) values.

These are guaranteed to be the smallest and largest `datetime` values, but `datetime.datetime.min == datetime.datetime.min` is still `True`; everything else is larger. The inverse is true for the `datatime.datetime.max` value.

There are also `min` and `max` values for `datetime.date` and `datetime.time`.
Reply

#3
Try this:

>>> import datetime
>>> datetime.datetime.max
datetime.datetime(9999, 12, 31, 23, 59, 59, 999999)

You can get `min`/`max` for `datetime`, `date`, and `time`.
Reply

#4
In case someone is using dates in Pandas dataframe:

>>> import pandas as pd
>>> pd.Timestamp.min
Timestamp('1677-09-21 00:12:43.145225')
>>> pd.Timestamp.max
Timestamp('2262-04-11 23:47:16.854775807')
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through