Format number

QuestionsFormat number
Robby asked 11 years ago

Dear Sir,

I have a field with date like this : yyyymmdd (20140101)
I want to display it as : dd/mm/yyyy.

All tests I did with dat format doesn't work.

Could you tell me how can I do it?

Thanks.

Rob

7 Answers
Abu Ghufran answered 11 years ago

Hello,

In sql query, you can use format_date function, to make it standard mysql date format. And then use grid date formatter.

e.g.

SELECT f1, f2, f3, date_format(str_to_date(mydate, '%Y%m%d'),'%Y-%m-%d') FROM table

Also check … http://stackoverflow.com/questions/11374557/how-to-convert-date-yyyymmdd-to-yy-mm-dd-in-mysql-query

Robby answered 11 years ago

Hi Abu,

I tried your solution and it works.
My command is:
SELECT *, date_format(Date_Inscription, '%d-%m-%Y') FROM MyTable";

In html file, I put:
$col = array();
$col["title"] = "Date";
$col["name"] = "date_format(Date_Inscription, '%d-%m-%Y')";
$col["width"] = "60";
$col["hidden"]= true;
$cols[] = $col;

In the grid, I have the date as I want (dd-mm-yyyy).
This is ok.
But I'm using the "showhidecolumns" option.

When I want to add or remove columns, I have an error message :
"Error: Syntax error, unrecognized expression: #col_date_format(Date_Inscription, '%d-%m-%Y')"

I don't know why?
Do you know how can I solve my problem?

The second thing.
I put :
$grid["width"] = 1000;

When I load my html page my grid takes the right size (1000).
But when I add columns, the grid increase without any limite.
Do you know how can I force my grid to still width=1000?

Thanks for your help.

Regards.

Robby

Abu Ghufran answered 11 years ago

Hello,

1) You can alias that field in sql to a simple name.
e.g.

SELECT *, date_format(Date_Inscription, '%d-%m-%Y') as mydate FROM MyTable";

$col["name"] = "mydate";
$col["dbname"] = "date_format(Date_Inscription, '%d-%m-%Y')";

2) Try setting

$grid["autofilter"] = false;
$grid["width"] = 1000;

Robby answered 11 years ago

Hi Abu,

Thanks for your solutions (date_format(..)..).
It works very well.

Concernint grid size, the 2 parameters you tell me was the one I use :
$grid["autofilter"] = false;
$grid["width"] = 1000;

But, it seems 1000 is the minimum.
If I remove columns, grid still at 1000 but if I add some grid increase.

Do you have any idea about where I'm wrong?

Thanks.

Robby

Abu Ghufran answered 11 years ago

Please review this:

Pasting from docs.

If set to true, and resizing the width of a column, the adjacent column (to the right) will resize so that the overall grid width is maintained (e.g., reducing the width of column 2 by 30px will increase the size of column 3 by 30px). In this case there is no horizontal scrolbar. Note: this option is not compatible with shrinkToFit option – i.e if shrinkToFit is set to false, forceFit is ignored.

$grid["forceFit"] = true;

Robby answered 11 years ago

Hi Abu,

I made the modification but it still doesn't work.
If I add columns, grid increase till become begger than screen.

I do not understand what I'm doing wrong.

Thanks.

Rob

Abu Ghufran answered 11 years ago

Please email me complete for review, along with db sql dump. ([email protected])
I'll review and regenerate this case.

Your Answer

3 + 1 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?