FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Windows Date Format
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Windows Date Format
Posted: Tue Jun 28, 2011 01:17 PM

Hi,

How can I get the "Short Date Format" from windows?

I would like to match my programs date format with what is setup in the windows regional settings.

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Windows Date Format
Posted: Tue Jun 28, 2011 05:07 PM
Jeff,

Maybe this old post by NageswaraRao will help.

James

------------------------------------------

Posted: Mon Jul 07, 2008 10:30 am Post subject:

--------------------------------------------------------------------------------

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:

Code (fw): Select all Collapse
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




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
_________________
Regards
NageswaraRao, G.
Hyderabad, India
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion