Welcome Guest Search | Active Topics | Log In | Register

Working with dates dmY Options
Pierre
#1 Posted : Friday, July 23, 2010 7:29:42 AM
Rank: Member

Groups: Registered

Joined: 7/15/2010
Posts: 12
Hello.

I'm working with dates formated like this in my database: dmY.
There is no separator.

I used a custom formatter to display thoses dates.

Code:

$grid->setColProperty("date", array("formatter"=>"js:colDate"));
$myformat = <<<FORMATFREIGHT
function colDate (cellValue, options, rowdata)
{
    var un = cellValue.substr(0, 2);
    var deux = cellValue.substr(2, 2);
    var trois = cellValue.substr(4, 4);
    return un+"/"+deux+"/"+trois;
}
FORMATFREIGHT;

This is working very well.

The issue is when I try to sort the column.
How may I do to sort them as dates?
I'm using the following code, but it don't seems to work.

Code:

// set the user date format to d/m/Y
$grid->setUserDate('d/m/Y');

// tell the grid which field is date
$grid->datearray = array('date');
rumen
#2 Posted : Sunday, July 25, 2010 10:41:53 PM
Rank: Administration

Groups: Administrators

Joined: 10/15/2009
Posts: 379
Hello Pierre,

Can you please try with formatter date and with formatoptions for src and new formats, e.g. something similar to this (but modified to match your case)

Code:
$grid->setColProperty("RequiredDate", array(
    "formatter"=>"date",
    "formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y"),
    )
);
Kind Regards,
Rumen Stankov (MCPD)
Trirand Inc.
Pierre
#3 Posted : Tuesday, July 27, 2010 1:06:37 AM
Rank: Member

Groups: Registered

Joined: 7/15/2010
Posts: 12
Hello Rumen.

I tried this:

Code:

$grid->setColProperty("MyDate", array(
    "formatter"=>"date",
    "formatoptions"=>array("srcformat"=>"dmY","newformat"=>"d/m/Y"),
    )
);
$grid->setColProperty("MyDate",
                      array("label"=>"Date entr&eacute;e",
                            "width"=>100,
                            "searchoptions"=>array("sopt"=>array("cn"))
                            )
);

A while ago I was using this:
Code:

$grid->setColProperty("MyDate",
                       array("label"=>"Date entr&eacute;e",
                             "width"=>100,
                             "searchoptions"=>array("sopt"=>array("cn")),
                             "formatter"=>"date",
                             "formatoptions"=>array("srcformat"=>"dmY",
                                                    "newformat"=>"d/m/Y")
                             )
);


The result is the same, with an input like this date : 14052007
I have the following output : 01/01/1970

It seems that when there is no separator in the date field, the date formater don't work. That's why I tried a custom formater.

Regards, Pierre
tony
#4 Posted : Wednesday, July 28, 2010 7:41:54 AM
Rank: Administration

Groups: Registered

Joined: 1/8/2010
Posts: 636
Location: Sofia, Bulgaria
Hello,
How is the problematic date field defined into the DataBase?
(please if possible do a table dump)
Which database is used?

Kind Regards
Tony Tomov
TriRand Inc
Pierre
#5 Posted : Thursday, July 29, 2010 12:36:52 AM
Rank: Member

Groups: Registered

Joined: 7/15/2010
Posts: 12
Hello Tony,

I'm using MySQL: 5.x

`MyDate` varchar(8) DEFAULT NULL,

Into the database my values are like this 01122007

With a custom formater, the output is ok but the sorting is not.

Regards, Pierre.
tony
#6 Posted : Thursday, July 29, 2010 1:10:30 AM
Rank: Administration

Groups: Registered

Joined: 1/8/2010
Posts: 636
Location: Sofia, Bulgaria
Hello,
I think that your sorting will not work correct, since the field is varchar and you want to interpret it as date. The grid recognizes this field as varchar and nothing more.
This is equivalent of

"SELECT MyDate, .... WHERE .... ORDER BY MyDate";

If you run this command into the SQL console you will have the same result.

One possible solution maybe is to use CAST function, where the database should convert the field to date field.

Kind Regards
Tony Tomov
TriRand Inc
Pierre
#7 Posted : Thursday, July 29, 2010 2:52:02 AM
Rank: Member

Groups: Registered

Joined: 7/15/2010
Posts: 12
Hello,

Thanks for the answer. I'll do like you said.

Btw TriRand team did a great job with jqGrid, thanks for that too.

Regards, Pierre.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.3 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.226 seconds.