Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Date() format
Message
De
18/12/2007 04:58:33
 
 
À
18/12/2007 03:18:42
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP
Divers
Thread ID:
01276414
Message ID:
01276428
Vues:
29
>How do you return today's date like this?
>
>Tuesday, December 18, 2007
>
>TIA.

Evelyn,

This should get you started. It repects the language of the user's computer

?Date_Format(date())

?Date_Format(date(), [dddd', 'dd MMM yyyy])

For other formats, see http://msdn2.microsoft.com/en-us/library/ms776293.aspx
You may want to force the locale
*--------------------------------------------------------------------------
function Date_Format(d, lpFormat)

	#define	DATE_SHORTDATE	0x00000001
	#define	DATE_LONGDATE	0x00000002

	#define	LOCALE_SYSTEM_DEFAULT	0x00000800
	#define	LOCALE_USER_DEFAULT		0x00000400	
	* LCID GetThreadLocale(void)
	
	declare long GetThreadLocale in win32api
	
	*int GetDateFormat(
	*  LCID Locale,               // locale
	*  DWORD dwFlags,             // options
	*  CONST SYSTEMTIME *lpDate,  // date
	*  LPCTSTR lpFormat,          // date format
	*  LPTSTR lpDateStr,          // formatted string buffer
	*  int cchDate                // size of buffer
	*);
	
	declare integer GetDateFormat in win32api ;
			long	Locale, ;
			long	dwFlags, ;
			string@	lpDate, ;
			String@	lpFormat, ;
			string@	lpDateStr, ;
			integer	cchDate
	
	local lpDate, lpFormat, DateFormatted, nchars
	lpDate = SystemTimeStruct(m.d)
	DateFormatted = space(128)
	
	do case
	case !inlist(vartype(m.d), T_DATE, T_DATETIME )
		assert FALSE
		return ''
	endcase
	
	lpFormat = iif(empty(m.lpFormat), [ddd', 'dd MMM yyyy], m.lpFormat)

	nchars = GetDateFormat( GetThreadLocale(), 0, @m.lpDate, @m.lpFormat, @m.DateFormatted, len(m.DateFormatted))
	&& GERMAN: nchars = GetDateFormat( 0x0407, 0, @m.lpDate, @m.lpFormat, @m.DateFormatted, len(m.DateFormatted))
         && ENGLISH: nchars = GetDateFormat( 0x0409, 0, @m.lpDate, @m.lpFormat, @m.DateFormatted, len(m.DateFormatted))
         && see : http://msdn2.microsoft.com/en-us/library/ms776260.aspx


	do case
	case empty(m.nchars)
		return ''
		
	case inlist(vartype(d), T_DATE)
		return left(m.DateFormatted, m.nchars-1)
		
	case inlist(vartype(d), T_DATETIME )
		return left(m.DateFormatted, m.nchars-1) + ' ' + ttoc(m.d,2)
	endcase
	
endfunc
*---------------------------------------------------------------------------
function SystemTimeStruct(d)

	local s
	
	do case
	case inlist(vartype(m.d), T_DATE, T_DATETIME )
		s =		BinToWord(year(m.d)) ;
			+	BinToWord(Month(m.d)) ;
			+	BinToWord(mod(dow(m.d,2),7)) ;
			+	BinToWord(day(m.d)) ;
			+	BinToWord(hour(m.d)) ;
			+	BinToWord(minute(m.d)) ;
			+	BinToWord(sec(m.d)) ;
			+	BinToWord(0)
			
	case vartype(m.d) == 'X'	&& null
		s =		BinToWord(0) ;
			+	BinToWord(0) ;
			+	BinToWord(0) ;
			+	BinToWord(0) ;
			+	BinToWord(0) ;
			+	BinToWord(0) ;
			+	BinToWord(0) ;
			+	BinToWord(0)
	otherwise
		assert FALSE
		s = ''
	endcase

	return m.s
endfunc
*---------------------------------------------------------------------------
function BinToWord(x)

	x = int(m.x)
	
	return	chr(bitand(m.x, 0xff)) + ;
			chr(bitand(bitrshift(m.x,  8), 0xff))

endfunc
*----------------------------------------------------------------------------
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform