View Full Version : Date and Time Difference
MIH1406
21st August 2009, 00:16
Hi,
Is there a class that return the difference between to given dates?
Thanks
Mohammad
ChrisW67
21st August 2009, 04:30
For days between two dates: Use the QDate class and its daysTo() function. Alternatively, convert both dates using toJulianDay() and subtract one from the other.
For finer grain than a whole day the QDateTime class has toTime_t(), which can be used in the same way as toJulianDay().
MIH1406
7th September 2009, 01:24
This is good
Thank you
Mohammad
hemapriya
19th August 2012, 06:59
i have a doubt..pls help..
i have 2 QDateEdits..ie one s start_date and other is end_date..i want to find difference between them and display in a QLineEdit..how to do it?
i did
int s=ui->start_date.day();
int e=ui->end_date.day();
int diff=e-s; //this works correctly it returns the difference
Qstring d=diff.toString(); //here am getting junk values y?
ui->line_edit->setText(d);
BalaQT
20th August 2012, 15:03
try daysTo() function.
Ex:
Qt Code: Switch view
QDate date1;
QDate date2;
int nDiff = date1.daysTo(date2);
ui->line_edit->setText(QString::number(nDiff));
To copy to clipboard, switch view to plain text mode
Qstring d=diff.toString(); //here am getting junk values y?
you need to convert the int to string ().
hope it helps
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.