in reply to Win32::GUI::Grid & Date Formats

Reformatting it doesn't seem that difficult. Here's a function that would do it:
sub Reformat { my @field = split( '-', shift()); my $result = $field[2]; for my $idx (0..1) { ( $field[ $idx ] < 10 ) and $field[ $idx ] = '0' . $field[ $idx ]; $result .= ( '-' . $field[ $idx ] ); } return $result; }

One world, one people

Replies are listed 'Best First'.
Re^2: Win32::GUI::Grid & Date Formats
by ChrisR (Hermit) on Jul 20, 2005 at 15:48 UTC
    Perhaps I need to do a little more clarification here. I do not need to format a date string. I need to et the control so that it formats the date string. The Win32::GUI::DateTime control, which is what I suspect Grid is using, can be set to use different dat/time format via the Format method. I just don't know how to access the DateTime object within the Grid Cell object so that it displays the correct format. Here is a short piece of code to demonstrate the issue:
    #!c:\perl\wperl.exe use strict; use Win32::GUI; use Win32::GUI::Grid; my $mainform = Win32::GUI::Window->new(-name=>'main',-text=>'Grid Date + Format Problem',-width=>810,-height=>625,-dialogui=>1); my $grid = $mainform->AddGrid(-name=>'grid',-pos=>[25,85],-rows=>2,-co +lumns=>3,-fixedrows=>1,-fixedcolumns=>1,-editable=>1,-size=> [520,400 +],-addstyle=>WS_VSCROLL|WS_TABSTOP); $grid->SetColumnWidth(0,100); $grid->SetColumnWidth(1,100); $grid->SetColumnWidth(2,100); $grid->SetRowHeight(1,30); $grid->SetCellText(0, 0, "ID"); $grid->SetCellText(0, 1, "GVIT_DATECAL"); $grid->SetCellText(0, 2, "GVIT_DATE"); $grid->SetCellFormat(1, 1, 'yyyy-MM-dd'); $grid->SetCellType(1, 1, GVIT_DATECAL); $grid->SetCellText(1, 1, "2005-07-19"); $grid->SetCellFormat(1, 2, 'yyyy-MM-dd'); $grid->SetCellType(1, 2, GVIT_DATE); $grid->SetCellText(1, 2, "2005-07-19"); $mainform->Show(); Win32::GUI::Dialog();
    The SetCellFormat method is probably not what I need to use here but I have no idea how to make it work. After you select a date using the control, the cell will display the date in whatever your short date format is. If you change your short date format and re-run the program, it will display in the new format you set. I want to ignore the default setting for the system and set the format myself.

    By the way, the code you provided doesn't work as far as I can tell. Whether I send it a date like 2005/7/19 or 7/19/2005 it returns something that doesn't look like a date to me.

    But again, thanks for replying.

    Chris
      I was in the process of thinking that your code was experiencing a date format problem between a db and the GUI. But I don't think this is the case. Looking at the screen everything displays correctly until you click in the cell that contains the date and then it changes to the current date in a different format. That is a little annoying. Is this the problem that you are talking about. Or, is it a db GUI format problem?

      Doug

        That is exactly what I'm talking about. The problem has nothing to do with a database or formatting a date string. The problem is that the DateTime control in the Grid is not doing what I need it to. A DateTime control can be formatted to do what I need as follows:
        my $datecontrol = $mainform->AddDateTime(-name=>"datecontrol",-lef +t=>10,-top=>500,-width=>150,-height=>30); $datecontrol->Format("yyyy-MM-dd"); $datecontrol->SetDate(19,7,2005); #day,month,year as specified in +the docs
        So, if I can access a DateTime object and set the format/properties like that, there has to be a way to access the same type of object that is embedded in the Grid Cell object. Doesn't there?? Perhaps I should have titled this node "How to access an embedded object" or "Win32::DateTime in Win32::GUI::Grid". My apologies to all if my OP was unclear.
      Not wanting to get too deep into the GUI at this stage, my first thought now is to set the type in the GUI to string and use the Date::Format module to do such general formatting and then repost the formatted string with the GUI methods.

      One world, one people

        Hmmm... If I use your function with 7-19-2005, I get 2005-19-01.
        A reply falls below the community's threshold of quality. You may see it by logging in.