Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the day of a Date

Tags:

qt

qt4

qt-creator

I want to find the day of the week of a particular date in Qt. e.g.: 1/05/2010 is Sunday.

Is it possible to find the weekday using date?

like image 218
Sijith Avatar asked May 24 '10 07:05

Sijith


People also ask

What is the shortcut to find day from date?

Step1 :Take the first two digit of the given year. Step2 :Calculate the next highest multiple of 4 for the first two digit number. Step3 :Subtract 1 from the number. Step4 :Then, subtract the first two digit from the number.


2 Answers

QDate date;
date.setDate(2010,5,1);
int day = date.dayOfWeek();
QString weekDay = QDate::longDayName(day);

This isn't tested. But hope it will work. Check it out and let know.

like image 68
liaK Avatar answered Nov 15 '22 10:11

liaK


int QDate::dayOfWeek () const

Returns the weekday (1 to 7) for this date.

For example,

QDate date;
date.setDate(2010, 5, 1);

switch (date.dayOfWeek()) {
 case 1:
  // Monday
  break;
 // etc...
}
like image 43
mosg Avatar answered Nov 15 '22 11:11

mosg