jeu. 07 juin 2012, 16h10
Gregory
atoutfox.public.association
Re: transform(d|t, 'format')
Non, mais avec un peu d’API, oui
Quant aux codes (format) voir
http://msdn.microsoft.com/en-us/library/windows/desktop/dd317787(v=vs.85).aspx
Aussi
http://msdn.microsoft.com/en-us/library/windows/desktop/dd318086(v=vs.85).aspx
*
function do it()
local obj, s
obj = createobject('collection')
=m.obj.add('')
=m.obj.Add([dddd', ' dd MMMM yyyy])
=m.obj.Add([MM'/'yyyy]) && a la excel
for each s in m.obj
?date(), FormatDate(date(), m.s)
endfor
endfunc
*
function FormatDate(d, sFormat)
local lpDate, lpFormat, dateFormatted, nchars
lpDate = SystemTimeStruct(m.d)
dateFormatted = space(128)
lpFormat = evl(m.sFormat, [ddd', 'dd MMM yyyy])
nchars = GetDateFormat( ;
GetThreadLocale(), ;
0, ;
@m.lpDate, ;
@m.lpFormat, ;
@m.dateFormatted, ;
len(m.dateFormatted) ;
)
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 GetDateFormat()
lparameters locale, ;
dwFlags, ;
lpDate, ;
lpFormat, ;
lpDateStr, ;
cchDate
local returnvalue
try
declare integer GetDateFormat in win32api ;
long locale, ;
long dwFlags, ;
string@ lpDate, ;
String@ lpFormat, ;
string@ lpDateStr, ;
integer cchDate
returnvalue = GetDateFormat( m.locale, m.dwFlags, @m.lpDate, @m.lpFormat, @m.lpDateStr, m.cchDate)
catch
returnvalue = 0
endtry
return m.returnvalue
endfunc
*
function GetThreadLocale()
local returnvalue
try
declare long GetThreadLocale in win32api
returnvalue = GetThreadLocale( )
catch
returnvalue = 0
endtry
return m.returnvalue
endfunc
*
function SystemTimeStruct(d)
local s
do case
case inlist(vartype(m.d), T DATE, T DATETIME )
s = bintoc(year(m.d), '2rs') ;
+ bintoc(Month(m.d), '2rs') ;
+ bintoc(mod(dow(m.d,2),7), '2rs') ;
+ bintoc(day(m.d), '2rs') ;
+ bintoc(hour(m.d), '2rs') ;
+ bintoc(minute(m.d), '2rs') ;
+ bintoc(sec(m.d), '2rs') ;
+ bintoc(0)
case vartype(m.d) == 'X' && null
s = bintoc(0) ;
+ bintoc(0) ;
+ bintoc(0) ;
+ bintoc(0) ;
+ bintoc(0) ;
+ bintoc(0) ;
+ bintoc(0) ;
+ bintoc(0)
otherwise
assert .f.
s = ''
endcase
return m.s
endfunc
*
Gregory
"FoxInCloud" wrote in message news:jqq9q0$2s4p$1@news.niouzes.net...
Bonjour,
Savez-vous si transforme() peut formater des dates avec des codes de type 'mm/yyyy' comme Excel?
merci
Permalink : http://www.atoutfox.org/nntp.asp?ID=0000009135