Date format in xBrowse
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Date format in xBrowse
Hi all,
I use in my app the 8 digit date format dd/mm/yy - yes I have to change it to 4 digit year and I will make it as soon as possible
At this moment I would like to use ONLY in a xbrowse (array) the dd/mm/yyyy format. Is there any way to use a specific date format only in the xbrowse without change the date format to all the app ?
Thanks.
I use in my app the 8 digit date format dd/mm/yy - yes I have to change it to 4 digit year and I will make it as soon as possible
At this moment I would like to use ONLY in a xbrowse (array) the dd/mm/yyyy format. Is there any way to use a specific date format only in the xbrowse without change the date format to all the app ?
Thanks.
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Date format in xBrowse
Code: Select all
FUNCTION MAIN()
LOCAL dDate := DATE()
? dDate
? STRZERO( DAY( dDate ), 2 ) + "/" + STRZERO( MONTH( dDate ), 2 ) + "/" + LTRIM( STR( YEAR( dDate ) ) )
RETURN NIL
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
I personally use my function "dtocfmt( <date>, <cformat> )", whenever I need to show date in a non-conventional format or a format different than the Set Date format.
In a case like this I would
bStrDate := { || dtocfmt( <datevar>, 'dd-mm-yyyy' ) }
Here is the source code of the function:
Format is case insenstive and date, month and year can be positioned anywhere.
Example formats and results:
dd-mm-yy ->22-07-08
dd-mmm-yyyy -> 22-Oct-2008
mmmm dd, yyyy -> October 02, 2008
mmm yyyy -> OCT 2008
In a case like this I would
bStrDate := { || dtocfmt( <datevar>, 'dd-mm-yyyy' ) }
Here is the source code of the function:
Code: Select all
function dtocfmt( dDate, cFormat )
local cDate
DEFAULT cFormat := Set( _SET_DATEFORMAT )
cDate := Lower( cFormat )
cDate := StrTran( cDate, 'dd', StrZero( Day( dDate ), 2 ) )
if 'mmmm' $ cDate
cDate := StrTran( cDate, 'mmmm', cMonth( dDate ) )
elseif 'mmm' $ cDate
cDate := StrTran( cDate, 'mmm', Left( cMonth( dDate ), 3 ) )
else
cDate := StrTran( cDate, 'mm', StrZero( Month( dDate ), 2 ) )
endif
if 'yyyy' $ cDate
cDate := StrTran( cDate, 'yyyy', Str( Year( dDate ), 4, 0 ) )
else
cDate := StrTran( cDate, 'yy', StrZero( Year( dDate ) % 100, 2 ) )
endif
return cDate
Example formats and results:
dd-mm-yy ->22-07-08
dd-mmm-yyyy -> 22-Oct-2008
mmmm dd, yyyy -> October 02, 2008
mmm yyyy -> OCT 2008
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Detlef Hoefner
- Posts: 312
- Joined: Sat Oct 08, 2005 9:12 am
- Location: Germany
- Contact:
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact:
Hi all,
thanks for the tips
but how can I use a specific date format on a xbrowse ?
This is a sample code that show the problem:
#include "FiveWin.ch"
#include "xbrowse.ch"
function Main()
local oDlg, oBrw, aArray
set century off && I can't change this
aArray:={}
aadd(aArray,{"First",ctod("01/01/2008")})
aadd(aArray,{"Second",ctod("01/04/2008")})
aadd(aArray,{"Thirth",ctod("01/06/2008")})
DEFINE DIALOG oDlg SIZE 300, 200
@ 0, 0 XBROWSE oBrw OF oDlg ARRAY aArray AUTOCOLS
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTER
return nil
If you execute this code you will see that the dates in the browse appair in the format dd/mm/yy due the century off setting.
I would like to display the dates in the browse in the format dd/mm/yyyy without change the century off setting.
Note that I need to leave a date format for the dates in the array in order to permit the customer to change the date order with a click on the header.
thanks for the tips
but how can I use a specific date format on a xbrowse ?
This is a sample code that show the problem:
#include "FiveWin.ch"
#include "xbrowse.ch"
function Main()
local oDlg, oBrw, aArray
set century off && I can't change this
aArray:={}
aadd(aArray,{"First",ctod("01/01/2008")})
aadd(aArray,{"Second",ctod("01/04/2008")})
aadd(aArray,{"Thirth",ctod("01/06/2008")})
DEFINE DIALOG oDlg SIZE 300, 200
@ 0, 0 XBROWSE oBrw OF oDlg ARRAY aArray AUTOCOLS
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTER
return nil
If you execute this code you will see that the dates in the browse appair in the format dd/mm/yy due the century off setting.
I would like to display the dates in the browse in the format dd/mm/yyyy without change the century off setting.
Note that I need to leave a date format for the dates in the array in order to permit the customer to change the date order with a click on the header.
Best Regards,
Marco Turco
SOFTWARE XP LLP
Marco Turco
SOFTWARE XP LLP
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Please insert this line before oBrw:CreateFromCode()
Include the source code of funtion dtocfmt I posted earlier either in the same module or in your libray
Code: Select all
oBrw:aCols[ 2 ]:bStrData := { || dtocfmt( oBrw:aRow[ 2 ], 'dd/mm/yyyy' ) }
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Marco,
Since your dates are in character format, you will actually have to do DTOS( CTOD( cDate ) ).
James
In order to do this you will need to use DTOS() otherwise dates in different years won't sort correctly. Since you don't want to display the dates in DTOS() format, you may have to either sort the array DTOS() then redisplay the browse when the user clicks the header, or create a temp dbf to hold the array, then create an index using DTOS(). With the dbf you can index on one format and display another.Note that I need to leave a date format for the dates in the array in order to permit the customer to change the date order with a click on the header.
Since your dates are in character format, you will actually have to do DTOS( CTOD( cDate ) ).
James
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
You may try this example.
Dates are stored in the array as date type only. Dates are sorted properly when the user clicks on the header because dates are stored in the date type only.
Dates can be showin in xbrowse in any format independant of the SetDate format. Also in this example, date format can be changed on the fly at any time. ( Right click on the date column pops up a menu to choose the date format and whatever format is chosen, dates are sorted properly )
Screenshots:
Dates are stored in the array as date type only. Dates are sorted properly when the user clicks on the header because dates are stored in the date type only.
Dates can be showin in xbrowse in any format independant of the SetDate format. Also in this example, date format can be changed on the fly at any time. ( Right click on the date column pops up a menu to choose the date format and whatever format is chosen, dates are sorted properly )
Code: Select all
#include 'fivewin.ch'
#include 'xbrowse.ch'
static cFormat := 'dd/mm/yyyy'
//----------------------------------------------------------------------------//
function Main()
local oDlg, oBrw, aArray
SET CENTURY OFF
aArray:={}
AAdd( aArray, { "First ", SToD("20080101") } )
AAdd( aArray, { "Second ", SToD("20080401") } )
AAdd( aArray, { "Third ", SToD("20080601") } )
DEFINE DIALOG oDlg SIZE 300, 200
@ 0, 0 XBROWSE oBrw OF oDlg ;
HEADERS 'Detail','Date' ;
SIZE 150,100 PIXEL ;
ARRAY aArray AUTOCOLS AUTOSORT
oBrw:aCols[ 2 ]:bStrData := { || dtocfmt( oBrw:aRow[ 2 ], cFormat ) }
oBrw:aCols[ 2 ]:bPopUp := { |o| ChooseDateFormat( o ) }
oBrw:nStretchCol := 2
oBrw:CreateFromCode()
ACTIVATE DIALOG oDlg CENTER
return nil
//----------------------------------------------------------------------------//
static function ChooseDateFormat( oCol )
local oPop
MENU oPop POPUP
MENUITEM 'dd/mm/yyyy' ACTION ( cFormat := oMenuItem:cPrompt, oCol:oBrw:Refresh() )
MENUITEM 'dd/mm/yy' ACTION ( cFormat := oMenuItem:cPrompt, oCol:oBrw:Refresh() )
MENUITEM 'mm/dd/yyyy' ACTION ( cFormat := oMenuItem:cPrompt, oCol:oBrw:Refresh() )
MENUITEM 'dd mmm yyyy' ACTION ( cFormat := oMenuItem:cPrompt, oCol:oBrw:Refresh() )
MENUITEM 'mmmm dd, yyyy' ACTION ( cFormat := oMenuItem:cPrompt, oCol:oBrw:Refresh() )
ENDMENU
return oPop
//----------------------------------------------------------------------------//
function dtocfmt( dDate, cFormat )
local cDate
DEFAULT cFormat := Set( _SET_DATEFORMAT )
cDate := Lower( cFormat )
cDate := StrTran( cDate, 'dd', StrZero( Day( dDate ), 2 ) )
if 'mmmm' $ cDate
cDate := StrTran( cDate, 'mmmm', cMonth( dDate ) )
elseif 'mmm' $ cDate
cDate := StrTran( cDate, 'mmm', Left( cMonth( dDate ), 3 ) )
else
cDate := StrTran( cDate, 'mm', StrZero( Month( dDate ), 2 ) )
endif
if 'yyyy' $ cDate
cDate := StrTran( cDate, 'yyyy', Str( Year( dDate ), 4, 0 ) )
else
cDate := StrTran( cDate, 'yy', StrZero( Year( dDate ) % 100, 2 ) )
endif
return cDate
//----------------------------------------------------------------------------//
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Marco Turco
- Posts: 858
- Joined: Fri Oct 07, 2005 12:00 pm
- Location: London
- Contact: