[Gambas-user] Grid View and Mysql Result, Time Data

Benoît Minisini gambas at ...1...
Fri Sep 18 18:58:35 CEST 2009


> I have a gridview control and i fill it with values from a mysql
> $RESULT with the next code
> 
> PUBLIC SUB grdView_Data(Row AS Integer, Column AS Integer)
> 
>   $Result.MoveTo(Row)
> 
>   grdView.Data.Text = Str($Result[grdView.Columns[Column].Text])
> 
> END
> 
> 
> The problem now.
> When value is Date with mysql format %Y-%m-%d
> the gridview shows "00:00:00" instead "0000:00:00" when the value of
> result is empty
> and change the format to %m/%d/%Y.
> 
> 
> For example see col4 which holds dates
> 
> mysql> SELECT * FROM `table4`;
> +------+------+------+------------+
> 
> | col1 | col2 | col3 | col4       |
> 
> +------+------+------+------------+
> 
> |    1 |   11 |  111 | 2008-09-24 |  <- %Y-%m-%d
> |    2 |   22 |  222 | 0000-00-00 |
> 
> +------+------+------+------------+
> 2 rows in set (0.00 sec)
> 
> And gridview shows
> 
> 09/24/08
> 
> Why is this? Normally the gridview must get the string " 2008-09-24"
> 

No. Gambas takes from MySQL the real date, and then you convert it to a string 
with the Str() function. The "mysql" program does the same thing, but uses its 
own "date to string" conversion functions.

If you want the same format, instead of using Str() (which is the better IMHO, 
as it follows the system localization settings), do that:

  grdView.Data.Text = Format($Result[grdView.Columns[Column].Text], 
                             "yyyy-mm-dd")

Regards,

-- 
Benoît Minisini




More information about the User mailing list