Qt Toolkit - QDate Class

# QDate Class Reference

The QDate class provides date functions. More...

`#include <qdatetime.h>`

List of all member functions.

## Public Members

- QDate ()
- QDate ( int y, int m, int d )
- bool isNull () const
- bool isValid () const
- int year () const
- int month () const
- int day () const
- int dayOfWeek () const
- int dayOfYear () const
- int daysInMonth () const
- int daysInYear () const
- virtual const char* monthName ( int month ) const
- virtual const char* dayName ( int weekday ) const
- QString toString () const
- bool setYMD ( int y, int m, int d )
- QDate addDays ( int days ) const
- int daysTo ( const QDate & ) const
- bool operator== ( const QDate & d ) const
- bool operator!= ( const QDate & d ) const
- bool operator< ( const QDate & d ) const
- bool operator<= ( const QDate & d ) const
- bool operator> ( const QDate & d ) const
- bool operator>= ( const QDate & d ) const

## Static Public Members

- QDate currentDate ()
- bool isValid ( int y, int m, int d )
- bool leapYear ( int year )

## Static Protected Members

- uint greg2jul ( int y, int m, int d )
- void jul2greg ( uint jd, int & y, int & m, int & d )

## Related Functions

(Note that these are not member functions.)

- QDataStream & operator<< (QDataStream & s, const QDate & d)
- QDataStream & operator>> (QDataStream & s, QDate & d)

## Detailed Description

The QDate class provides date functions.

The QDate is based on the Gregorian (modern western) calendar. England adopted the Gregorian calendar on September 14th 1752, which is the earliest date that is supported by QDate. Using earlier dates will give undefined results. Some countries adopted the Gregorian calendar later than England, thus the week day of early dates might be incorrect for these countries (but correct for England). The end of time is reached around 8000AD, by which time we expect Qt to be obsolete.

See also: QTime and QDateTime.

Examples: dclock/dclock.cpp

## Member Function Documentation

### QDate::QDate ()

Constructs a null date. Null dates are invalid.

### QDate::QDate ( int y, int m, int d )

Constructs a date with the year y, month m and day d.

### QDate QDate::addDays ( int ndays ) const

Returns this date plus ndays days.

### QDate QDate::currentDate () `[static]`

Returns the current date.

See also: QTime::currentTime() and QDateTime::currentDateTime().

### int QDate::day () const

Returns the day of the month (1..31) for this date.

See also: year(), month() and dayOfWeek().

Examples: dclock/dclock.cpp

### const char * QDate::dayName ( int weekday ) const `[virtual]`

Returns the name of the weekday.

Weekday 1 == "Mon", day 2 == "Tue" etc.

### int QDate::dayOfWeek () const

Returns the weekday (Monday=1 .. Sunday=7) for this date.

See also: day().

### int QDate::dayOfYear () const

Returns the day of the year (1..365) for this date.

### int QDate::daysInMonth () const

Returns the number of days in the month (28..31) for this date.

### int QDate::daysInYear () const

Returns the number of days in the year (365 or 366) for this date.

### int QDate::daysTo ( const QDate & d ) const

Returns the number of days from this date to d, which is negative if d is in the past.

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().

### uint QDate::greg2jul ( int y, int m, int d ) `[static protected]`

For internal use only.

### bool QDate::isNull () const

Returns TRUE if the date is null. A null date is invalid.

See also: isValid().

### bool QDate::isValid () const

Returns TRUE if the date is valid.

See also: isNull().

### bool QDate::isValid ( int y, int m, int d ) `[static]`

Returns TRUE if the specified date is valid.

Note that years 00-99 are treated as 1900-1999.

See also: isNull().

### void QDate::jul2greg ( uint jd, int & y, int & m, int & d ) `[static protected]`

For internal use only.

### bool QDate::leapYear ( int y ) `[static]`

Returns TRUE if the specified year y is a leap year.

### int QDate::month () const

Returns the month (January=1 .. December=12) for this date.

See also: year() and day().

Examples: dclock/dclock.cpp

### const char * QDate::monthName ( int month ) const `[virtual]`

Returns the name of the month.

Month 1 == "Jan", month 2 == "Feb" etc.

### bool QDate::operator!= ( const QDate & d ) const

Returns TRUE if this date is different from d, or FALSE if they are equal.

### bool QDate::operator< ( const QDate & d ) const

Returns TRUE if this date is before d, otherwise FALSE.

### bool QDate::operator<= ( const QDate & d ) const

Returns TRUE if this date is before or equal to d, otherwise FALSE.

### bool QDate::operator== ( const QDate & d ) const

Returns TRUE if this date is equal to d, or FALSE if they are different.

### bool QDate::operator> ( const QDate & d ) const

Returns TRUE if this date is after d, otherwise FALSE.

### bool QDate::operator>= ( const QDate & d ) const

Returns TRUE if this date is equal to or after d, otherwise FALSE.

### bool QDate::setYMD ( int y, int m, int d )

Sets the year y, month m and day d. Returns TRUE if the date is valid, otherwise FALSE.

### QString QDate::toString () const

Returns the date as a string.

The string format is "Sat May 20 1995".

### int QDate::year () const

Returns the year (>= 1752) for this date.

See also: month() and day().

## Related Functions

### QDataStream & operator<< (QDataStream & s, const QDate & d)

Writes the date to the stream.

Serialization format: [Q_UINT32], Julian day.

### QDataStream & operator>> (QDataStream & s, QDate & d)

Reads a date from the stream.

Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):

This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.

It was generated from the following files:

- qdatetime.h: 1998/08/25
- qdatetime.cpp: 1999/02/15