PDA

View Full Version : Export the data in between a specified time range from Sql DB to Excel



maveric
12th June 2008, 06:57
Hi friends i have a small problem, I have a sqlite db in which there is a time range say from 17:30:35 to 17:45:55 now i have used two Q3TimeEdit to select the starting and The Ending Time and to export the selected time range values to excel.


void testexport::on_pushButton_4_clicked()
{
QTime time1 = Q3TimeEdit->time();
QTime time2 = Q3TimeEdit_2->time();
time_range.clear();
QStringList time_fields;
QSqlQuery time_query_header("select * from Plotting_data1 where 1=0"); //don't actually select anything but get a reference to the record set
QSqlRecord time_header_count = time_query_header.record();
QSqlQuery range("SELECT * FROM Plotting_data1 where Time>= ''time1" and Time<="time2"); // I get an error i tried so many things but i don get the desired o/p


In .Net ("SELECT * FROM Plotting_data1 where Time>= ' '' +time1+ " ' and Time<= ' '' +time2+ " ' "); by doing this i got the values in between the Start time and end time to excel. What do i need to do for Qt

When i pass the time directly i get the values between the intervals which i have specified,But when i try to pass it from the Q3TimeEdit i don't get.
QSqlQuery range("SELECT * FROM Plotting_data1 where Time>= '17:30:35' and Time<='17:35:55'"); // How to pass the values i have given in the Q3TimeEdit i have used.

mazurekwrc
12th June 2008, 07:38
read here about bindValue function
http://doc.trolltech.com/4.4/qsqlquery.html

maveric
12th June 2008, 10:20
Hi,

Thanks for the link. It din help me. But i some how solved my problem .!!!


Thankx

patrik08
12th June 2008, 11:59
SELECT * FROM Plotting_data1 where Time>= '17:30:35' and Time<='17:35:55

and order by Time???

I think only oracle cam make this.....


Use the UnixTime is more efficient!
all os can handle ....

on mysql
select a,FROM_UNIXTIME(timebounce,'%d.%c.%Y'),....
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

or



QDateTime times;
times.setTime_t(resultunixtime);




QDateTime timer1( QDateTime::currentDateTime() );
const uint now = timer1.toTime_t();


1213268102 = Date: Thu, 12 Jun 2008 12:55:02
1213268103 = Date: Thu, 12 Jun 2008 12:55:03
0 = 1.1.1970

on sql order by time desc the new come first && old last...