[Gambas-user] Problems with results from mysql
Benoit Minisini
gambas at ...1...
Wed Apr 6 11:29:35 CEST 2005
On Monday 04 April 2005 19:55, Rolf Schmidt wrote:
> Hi
>
> I wrote a small application to collect my bicycle kilometers and show my
> fitness. The time I sit on the bicycle is stored in seconds but I let MySQL
> give me the sum in hours, minutes and scecons.
>
> Here the query and the result as shown by the mysql-client:
>
> select sec_to_time(sum(dauersekunden)) as dat ,
> sum(kilometer) as km
> from daten where datum between '2005-01-01' and
> '2005-12-31'; +----------+---------+
>
> | dat | km |
>
> ----------+---------+
>
> | 26:40:11 | 613.042 |
>
> +----------+---------+
> 1 row in set (0.00 sec)
>
> As one can see, the time is given in hours.
>
> Gambas shows the result as: "01.01.-4801 01:30:11"
> Here the gambas code:
> request = "select sec_to_time(sum(dauersekunden)) as dat, sum(kilometer)
> " & " as km from daten where datum between '"
> request = request & Year(Now) & "-01-01' and '" & Year(Now) & "-12-31' "
> myresult = hDB.Exec(request)
> IF (abfrage.Count > 0) THEN
> TextLabel1.text = "Duration: " & myresult["dat"] & " Std."
> Textlabel2.text = "Length: " & myresult["km"] & " km"
> ELSE
> Textlabel1.visible = FALSE
> TextLabel2.visible = FALSE
> END IF
>
> Even in the gambas debugger the value "01.01.-4801 01:30:11" is shown, So
> where take the conversion place and how could I get the right values?
>
> Bye
> Rolf
Actually, Gambas make no distinction between time and hours. So it converts
your time-only field into an date/time field.
I think you can get the correct value this way:
PRINT "Number of hours: "; CFloat(myresult!dat) * 24
To get the minutes and seconds, you must do the conversion by yourself.
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
More information about the User
mailing list