QDate(3qt)
β¨ NAME β¨
QDate(3qt) β Date functions. π
π SYNOPSIS π
All the functions in this class are reentrant when Qt is built with thread support.</p>
#include <qdatetime.h>
π Public Members π
QDate ()QDate ( int y, int m, int d )bool isNull () constbool isValid () constint year () constint month () constint day () constint dayOfWeek () constint dayOfYear () constint daysInMonth () constint daysInYear () constint weekNumber ( int * yearNumber = 0 ) constQString toString ( Qt::DateFormat f = Qt::TextDate ) constQString toString ( const QString & format ) constbool setYMD ( int y, int m, int d )QDate addDays ( int ndays ) constQDate addMonths ( int nmonths ) constQDate addYears ( int nyears ) constint daysTo ( const QDate & d ) constbool operator== ( const QDate & d ) constbool operator!= ( const QDate & d ) constbool operator< ( const QDate & d ) constbool operator<= ( const QDate & d ) constbool operator> ( const QDate & d ) constbool operator>= ( const QDate & d ) const
π Static Public Members π
QString monthName ( int month )(obsolete)QString dayName ( int weekday )(obsolete)QString shortMonthName ( int month )QString shortDayName ( int weekday )QString longMonthName ( int month )QString longDayName ( int weekday )QDate currentDate ()QDate currentDate ( Qt::TimeSpec ts )QDate fromString ( const QString & s, Qt::DateFormat f = Qt::TextDate )bool isValid ( int y, int m, int d )bool leapYear ( int y )
π RELATED FUNCTION DOCUMENTATION π
QDataStream & operator<< ( QDataStream & s, const QDate & d )QDataStream & operator>> ( QDataStream & s, QDate & d )
πΈ DESCRIPTION πΈ
The QDate class provides date functions. ποΈβ¨
A QDate object contains a calendar date, i.e. year, month, and day numbers, in the modern Western (Gregorian) calendar. It can read the current date from the system clock. It provides functions for comparing dates and for manipulating dates, e.g. by adding a number of days or months or years. No cap. π―
A QDate object is typically created either by giving the year, month and day numbers explicitly, or by using the static function currentDate(), which creates a QDate object containing the system clock's date. An explicit date can also be set using setYMD(). The fromString() function returns a QDate given a string and a date format which is used to interpret the date within the string. So many ways to get your date on. π
The year(), month(), and day() functions provide access to the year, month, and day numbers. Also, dayOfWeek() and dayOfYear() functions are provided. The same information is provided in textual format by the toString(), shortDayName(), longDayName(), shortMonthName() and longMonthName() functions. It's giving very versatile. π
QDate provides a full set of operators to compare two QDate objects where smaller means earlier and larger means later. Slay those comparisons. π₯
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. Math but make it date. β¨
The daysInMonth() and daysInYear() functions return how many days there are in this date's month and year, respectively. The leapYear() function indicates whether this date is in a leap year. Leap years are iconic. πΈ
Note:QDateshould not be used for date calculations for dates prior to the introduction of the Gregorian calendar. This calendar was adopted by England from the 14<sup><small>th</small></sup> September 1752 (hence this is the earliest validQDate), and subsequently by most other Western countries, until 1923. So don't come for it with your 1202 dates. π«
The end of time is reached around the year 8000, by which time we expect Qt to be obsolete. LMAO bye. π
See also QTime, QDateTime, QDateEdit, QDateTimeEdit, and Time and Date. π«Ά
π MEMBER FUNCTION DOCUMENTATION π
QDate::QDate ()
Constructs a null date. Null dates are invalid. So if you want a valid date, this ain't it, bestie. π
See also isNull() and isValid().
QDate::QDate ( int y, int m, int d )
Constructs a date with year y, month m and day d. π
y must be in the range 1752..8000, m must be in the range 1..12, and d must be in the range 1..31. Respect the ranges. β
Warning: Ifyis in the range0..99, it is interpreted as1900..1999. So watch out for that sneaky two-digit year. π±
See also isValid().
QDate QDate::addDays ( int ndays ) const
Returns a QDate object containing a date ndays later than the date of this object (or earlier if ndays is negative). Time travel but make it days. β³
See also addMonths(), addYears(), and daysTo().
QDate QDate::addMonths ( int nmonths ) const
Returns a QDate object containing a date nmonths later than the date of this object (or earlier if nmonths is negative). Month by month, we get it. π
See also addDays() and addYears().
QDate QDate::addYears ( int nyears ) const
Returns a QDate object containing a date nyears later than the date of this object (or earlier if nyears is negative). Year after year, iconic. ποΈ
See also addDays() and addMonths().
QDate QDate::currentDate ( Qt::TimeSpec ts ) [static]
Returns the current date, as reported by the system clock, for the TimeSpec ts. The default TimeSpec is LocalTime. So you get the now. π°οΈ
See also QTime::currentTime(), QDateTime::currentDateTime(), and Qt::TimeSpec.
Example: dclock/dclock.cpp.
QDate QDate::currentDate () [static]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. So same vibe, no ts needed. πββοΈ
Returns the current date, as reported by the system clock.
See also QTime::currentTime() and QDateTime::currentDateTime().
int QDate::day () const
Returns the day of the month (1..31) of this date. Just the day, bestie. π
See also year(), month(), and dayOfWeek().
Example: dclock/dclock.cpp.
QString QDate::dayName ( int weekday ) [static]
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code. It's giving legacy. π΅
Use shortDayName() instead. That's the upgrade. β¨
int QDate::dayOfWeek () const
Returns the weekday (Monday=1..Sunday=7) for this date. So Monday is 1, Sunday is 7. No cap. ποΈ
See also day() and dayOfYear().
int QDate::dayOfYear () const
Returns the day of the year (1..365) for this date. Just the number. π€·ββοΈ
See also day() and dayOfWeek().
int QDate::daysInMonth () const
Returns the number of days in the month (28..31) for this date. February said 28 or 29, depending. ποΈ
See also day() and daysInYear().
int QDate::daysInYear () const
Returns the number of days in the year (365 or 366) for this date. Leap year? 366. Non-leap? 365. Simple. β¨
See also day() and daysInMonth().
int QDate::daysTo ( const QDate & d ) const
Returns the number of days from this date to d (which is negative if d is earlier than this date). So if you go backwards, it's negative. Math. π
Example:
QDate d1( 1995, 5, 17 ); // May 17th 1995
QDate d2( 1995, 5, 20 ); // May 20th 1995
d1.daysTo( d2 ); // returns 3
d2.daysTo( d1 ); // returns -3
See also addDays().
QDate QDate::fromString ( const QString & s, Qt::DateFormat f = Qt::TextDate ) [static]
Returns the QDate represented by the string s, using the format f, or an invalid date if the string cannot be parsed. So if it can't figure it out, you get invalid. π
ββοΈ
Note for Qt::TextDate: It is recommended that you use the English short month names (e.g. "Jan"). Although localized month names can also be used, they depend on the user's locale settings. So "Jan" is safe, but "janvier" might depend on where you at. π
Warning: Qt::LocalDate cannot be used here. Don't even try it. π«
bool QDate::isNull () const
Returns TRUE if the date is null; otherwise returns FALSE. A null date is invalid. So if it's null, it's not valid. Periodt. π
See also isValid().
bool QDate::isValid () const
Returns TRUE if this date is valid; otherwise returns FALSE. Simple. β
See also isNull().
bool QDate::isValid ( int y, int m, int d ) [static]
This is an overloaded member function, provided for convenience. It behaves essentially like the above function. So you can check a date without making an object. π
Returns TRUE if the specified date (year y, month m and day d) is valid; otherwise returns FALSE. Let's see some examples. π
Example:
QDate::isValid( 2002, 5, 17 ); // TRUE May 17th 2002 is valid
QDate::isValid( 2002, 2, 30 ); // FALSE Feb 30th does not exist
QDate::isValid( 2004, 2, 29 ); // TRUE 2004 is a leap year
QDate::isValid( 1202, 6, 6 ); // FALSE 1202 is pre-Gregorian
Warning: Ayvalue in the range00..99is interpreted as1900..1999. Again with the two-digit year. π
See also isNull() and setYMD().
bool QDate::leapYear ( int y ) [static]
Returns TRUE if the specified year y is a leap year; otherwise returns FALSE. Leap year check, slay. πΈβ¨
QString QDate::longDayName ( int weekday ) [static]
Returns the long name of the weekday. π
1 = "Monday", 2 = "Tuesday", ... 7 = "Sunday"
The day names will be localized according to the system's locale settings. So it might be in your language. π
See also toString(), shortDayName(), shortMonthName(), and longMonthName().
QString QDate::longMonthName ( int month ) [static]
Returns the long name of the month. ποΈ
1 = "January", 2 = "February", ... 12 = "December"
The month names will be localized according to the system's locale settings. Ooh la la. π«π·
See also toString(), shortMonthName(), shortDayName(), and longDayName().
int QDate::month () const
Returns the month (January=1..December=12) of this date. So January is 1, December is 12. Got it. π
See also year() and day().
Example: dclock/dclock.cpp.
QString QDate::monthName ( int month ) [static]
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code. It's giving old school. π
Use shortMonthName() instead. That's the move. π
bool QDate::operator!= ( const QDate & d ) const
Returns TRUE if this date is different from d; otherwise returns FALSE. Not equal, periodt. π«
bool QDate::operator< ( const QDate & d ) const
Returns TRUE if this date is earlier than d, otherwise returns FALSE. Earlier = less than. βͺ
bool QDate::operator<= ( const QDate & d ) const
Returns TRUE if this date is earlier than or equal to d, otherwise returns FALSE. Less than or equal, bestie. βͺ=
bool QDate::operator== ( const QDate & d ) const
Returns TRUE if this date is equal to d; otherwise returns FALSE. Equal? Slay. π―
bool QDate::operator> ( const QDate & d ) const
Returns TRUE if this date is later than d, otherwise returns FALSE. Later = greater than. β©
bool QDate::operator>= ( const QDate & d ) const
Returns TRUE if this date is later than or equal to d, otherwise returns FALSE. Greater than or equal, iconic. β©=
bool QDate::setYMD ( int y, int m, int d )
Sets the date's year y, month m and day d. π
y must be in the range 1752..8000, m must be in the range 1..12, and d must be in the range 1..31. Same rules as the constructor. β
Warning: Ifyis in the range0..99, it is interpreted as1900..1999. That two-digit year again. π€
Returns TRUE if the date is valid; otherwise returns FALSE. So check the return, bestie. β
QString QDate::shortDayName ( int weekday ) [static]
Returns the name of the weekday. π
1 = "Mon", 2 = "Tue", ... 7 = "Sun"
The day names will be localized according to the system's locale settings. So it might be "lun" in French. π
See also toString(), shortMonthName(), longMonthName(), and longDayName().
QString QDate::shortMonthName ( int month ) [static]
Returns the name of the month. ποΈ
1 = "Jan", 2 = "Feb", ... 12 = "Dec"
The month names will be localized according to the system's locale settings. So "Jan" might become "janv" in French. π«π·
See also toString(), longMonthName(), shortDayName(), and longDayName().
QDate::toString ( const QString & format ) const
okay bestie, this one is the glow-up function π
β it hands you back the date as a QString, and the format parameter is the one calling the shots on how that string looks.
The expressions you can use in that format string are listed in a table right here β but the plain-text man page flattened it into a little placeholder thing that reads \<center>.nf`β¦`</center>`` π so the actual expression list didn't survive the trip. It's genuinely there in the real docs, promise, this text version just ate it. Check the HTML docs for the full menu of format expressions, bestie.
Every other input character that isn't one of those expressions? Ignored. Straight up. It's giving "I don't see it, so it's not there." β¨
There's also a table of example format strings β assuming the QDate is the 20<sup><small>th</small></sup> July 1969 β and that table also got smooshed into a <center>.nf placeholder in this text version π so again, HTML docs for the receipts.
Heads up: if the date is an invalid date, then QString::null gets returned. Not an error, not an exception, just null. That's the vibe check and it failed. π
See also QDateTime::toString() and QTime::toString().
QDate::toString ( Qt::DateFormat f = Qt::TextDate ) const
This is an overloaded member function, provided for convenience π It behaves essentially like the above function.
Returns the date as a string, and the f parameter decides the format. Here's the breakdown, no cap:
- If
fisQt::TextDate, the string format is"Sat May 20 1995"β and it builds that using theshortDayName()andshortMonthName()functions, which means the day and month names are locale specific. So it'll speak your system's language, literally. π - If
fisQt::ISODate, the string format corresponds to the ISO 8601 specification for representations of dates, which isYYYY-MM-DDwhereYYYYis the year,MMis the month of the year (between01and12), andDDis the day of the month between01and31. International, standardised, iconic. π - If
fisQt::LocalDate, the string format depends on the locale settings of the system. It's giving "whatever your machine woke up feeling today." π¦
And same as before, bestie: if the date is an invalid date, then QString::null will be returned. Null. Nothing. The void. π³οΈ
See also shortDayName() and shortMonthName().
int QDate::weekNumber ( int * yearNumber = 0 ) const
This one tells you which week of the year you're in β returns the week number (1 to 53), and it stashes the year into *yearNumber unless yearNumber is null (which is the default, so if you pass nothing, it just quietly doesn't write anywhere π).
Returns 0 if the date is invalid. Zero. The "no week for you" answer.
In accordance with ISO 8601, weeks start on Monday and the first Thursday of a year is always in week 1 of that year. Most years have 52 weeks, but some have 53. Slay for the leap-week girlies. β¨
And here's the part that trips everyone up: *yearNumber is not always the same as year(). For example, 1 January 2000 has week number 52 in the year 1999, and 31 December 2002 has week number 1 in the year 2003. It's giving main character energy at the boundary of the calendar π
Now, the original page also drops a whole chunk of legal text right here in the middle of this function, which is honestly so real of it:
Copyright (c) 1989 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley. The name of the University may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
See also isValid().
int QDate::year () const
Returns the year (1752..8000) of this date. That's the range, bestie β 1752 to 8000, no more, no less. ποΈ
See also month() and day().
β¨ RELATED FUNCTION DOCUMENTATION β¨
QDataStream & operator<< ( QDataStream & s, const QDate & d )
Writes the date, d, to the data stream, s. Push it out, bestie, stream it like it's a storytime. π€
See also Format of the QDataStream operators.
QDataStream & operator>> ( QDataStream & s, QDate & d )
Reads a date from the stream s into d. Pull it back in, it knows where it's been. π₯
See also Format of the QDataStream operators.
π SEE ALSO π
π COPYRIGHT π
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
π AUTHOR π
Generated automatically from the source code. (Not a human. Not even a little bit. The robots did this one. π€β¨)
π¦ BUGS π¦
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. π (fr fr, a good bug report is a love letter to every dev who comes after you π)
The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. (Which, honestly, explains the smooshed tables up there π the man page is the side quest, the HTML is the main quest.)
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qdate.3qt) and the Qt version (3.3.8). Give them the receipts, bestie β name and version, every time. π
okay that's the whole page, we did it π₯³ this one was cranked out by Trolltech AS and it's dated 2 February 2007, and the page answers to the name QDate(3qt) β that's your footer, that's the signature, that's the little bow on top ππ go forth and format your dates, bestie. periodt. β¨π¦π
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms