Skip to content

PythonQt.QtCore.QDate

QDate

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

A QDate object represents a particular day, regardless of calendar, locale or other settings used when creating it or supplied by the system. It can report the year, month and day of the month that represent the day with respect to the proleptic Gregorian calendar or any calendar supplied as a QCalendar object.

A QDate object is typically created by giving the year, month, and day numbers explicitly. Note that QDate interprets year numbers less than 100 as presented, i.e., as years 1 through 99, without adding any offset. The static function currentDate() creates a QDate object containing the date read from the system clock. An explicit date can also be set using setDate(). The fromString() function returns a QDate given a string and a date format which is used to interpret the date within the string.

The year(), month(), and day() functions provide access to the year, month, and day numbers. When more than one of these values is needed, it is more efficient to call QCalendar::partsFromDate(), to save repeating (potentially expensive) calendrical calculations.

Also, dayOfWeek() and dayOfYear() functions are provided. The same information is provided in textual format by toString(). QLocale can map the day numbers to names, QCalendar can map month numbers to names.

QDate provides a full set of operators to compare two QDate objects where smaller means earlier, and larger means later.

You can increment (or decrement) a date by a given number of days using addDays(). Similarly you can use addMonths() and addYears(). The daysTo() function returns the number of days between two dates.

The daysInMonth() and daysInYear() functions return how many days there are in this date's month and year, respectively. The isLeapYear() function indicates whether a date is in a leap year. QCalendar can also supply this information, in some cases more conveniently.

Remarks

No Year 0

In the Gregorian calendar, there is no year 0. Dates in that year are considered invalid. The year -1 is the year "1 before Christ" or "1 before common era." The day before 1 January 1 CE, QDate(1, 1, 1), is 31 December 1 BCE, QDate(-1, 12, 31). Various other calendars behave similarly; see QCalendar::hasYearZero().

Range of Valid Dates

Dates are stored internally as a Julian Day number, an integer count of every day in a contiguous range, with 24 November 4714 BCE in the Gregorian calendar being Julian Day 0 (1 January 4713 BCE in the Julian calendar). As well as being an efficient and accurate way of storing an absolute date, it is suitable for converting a date into other calendar systems such as Hebrew, Islamic or Chinese. The Julian Day number can be obtained using QDate::toJulianDay() and can be set using QDate::fromJulianDay().

The range of Julian Day numbers that QDate can represent is, for technical reasons, limited to between -784350574879 and 784354017364, which means from before 2 billion BCE to after 2 billion CE. This is more than seven times as wide as the range of dates a QDateTime can represent.

Source: https://doc.qt.io/archives/qt-5.15/qdate.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
DateFormat attribute Any
MonthNameType attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
StandaloneFormat attribute Any
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
addDays function (self, days: int) -> Any X.addDays(days) -> PythonQt.QtCore.QDate
addMonths function (self, months: int) -> Any X.addMonths(months) -> PythonQt.QtCore.QDate
addYears function (self, years: int) -> Any X.addYears(years) -> PythonQt.QtCore.QDate
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
currentDate function (self) -> Any X.currentDate() -> PythonQt.QtCore.QDate
day function (self) -> int X.day() -> int
dayOfWeek function (self) -> int X.dayOfWeek() -> int
dayOfYear function (self) -> int X.dayOfYear() -> int
daysInMonth function (self) -> int X.daysInMonth() -> int
daysInYear function (self) -> int X.daysInYear() -> int
daysTo function (self, arg__1: Any) -> int X.daysTo(arg__1) -> int
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
fromJulianDay function (self, jd_: int) -> Any X.fromJulianDay(jd_) -> PythonQt.QtCore.QDate
fromString function (self, s: str, f: Any) -> Any X.fromString(s, f) -> PythonQt.QtCore.QDate
getDate function (self, year: Any, month: Any, day: Any) -> Any X.getDate(year, month, day)
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
isLeapYear function (self, year: int) -> bool X.isLeapYear(year) -> bool
isNull function (self) -> bool X.isNull() -> bool
isValid function (self, m: Any, d: Any) -> bool X.isValid(m, d) -> bool
longDayName function (self, weekday: int, type: Any) -> str X.longDayName(weekday, type) -> str
longMonthName function (self, month: int, type: Any) -> str X.longMonthName(month, type) -> str
month function (self) -> int X.month() -> int
readFrom function (self, arg__1: Any) -> Any (shared captured text)
setDate function (self, year: int, month: int, day: int) -> bool X.setDate(year, month, day) -> bool
shortDayName function (self, weekday: int, type: Any) -> str X.shortDayName(weekday, type) -> str
shortMonthName function (self, month: int, type: Any) -> str X.shortMonthName(month, type) -> str
toJulianDay function (self) -> int X.toJulianDay() -> int
toString function (self, f: Any) -> str X.toString(f) -> str
weekNumber function (self, yearNum: Any) -> int X.weekNumber(yearNum) -> int
writeTo function (self, arg__1: Any) -> Any (shared captured text)
year function (self) -> int X.year() -> int