Windows Date Format

Windows Date Format

Postby Jeff Barnes » Tue Jun 28, 2011 1: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)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Windows Date Format

Postby James Bott » Tue Jun 28, 2011 5: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: Select all  Expand view
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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 106 guests