well,
1/ Here is a short and handy cross-platform solution (but not localized) :
Code: Select all
Macro FormatDate2(mask, date)
FormatDate(ReplaceString(ReplaceString(mask,"%ddd",StringField("Sun,Mon,Tue,Wed,Thu,Fri,Sat",DayOfWeek(date)+1,",")),"%mmm",StringField("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec",Month(date),",")),date)
EndMacro
Debug FormatDate2("%dd.%mm.%yyyy %hh:%ii:%ss", Date())
Debug FormatDate2("%ddd %dd %mmm %yyyy %hh:%ii:%ss", Date())
2/ Even if i don't care about Win95 nor NT4, here is a compatible one :
Code: Select all
Procedure.s GetDateFormat(mask.s, date.l)
Protected st.SYSTEMTIME, result.s = Space(64)
st\wDay = Day (date)
st\wMonth = Month(date)
st\wYear = Year (date)
If GetDateFormat_(#LOCALE_USER_DEFAULT, 0, @st, mask, @result, 64)
ProcedureReturn UCase(Left(result, 1)) + Right(result, Len(result) - 1)
EndIf
EndProcedure
Procedure.s FormatDate2(mask.s, date.l)
mask = ReplaceString(mask, "%dddd", GetDateFormat("dddd", date))
mask = ReplaceString(mask, "%ddd", GetDateFormat("ddd", date))
mask = ReplaceString(mask, "%mmmm", GetDateFormat("MMMM", date))
mask = ReplaceString(mask, "%mmm", GetDateFormat("MMM", date))
ProcedureReturn FormatDate(mask, date)
EndProcedure
Debug FormatDate2("%ddd %dd %mmm %yyyy %hh:%ii:%ss", Date())
Debug FormatDate2("%dddd %dd %mmmm %yyyy %hh:%ii:%ss", Date())
3/ And another localized function for Windows 98 and later :
Code: Select all
Import "kernel32.lib"
GetCalendarInfoA(lcID.l, calID.l, calType.l, *lpCalData, cchData.l, *lpValue)
EndImport
Procedure.s GetCalendarInfo(type.l)
Protected result.s = Space(64)
If GetCalendarInfoA(#LOCALE_USER_DEFAULT, #CAL_GREGORIAN, type, @result, 64, 0)
ProcedureReturn UCase(Left(result, 1)) + Right(result, Len(result) - 1)
EndIf
EndProcedure
Procedure.s FormatDate2(mask.s, date.l)
mask = ReplaceString(mask, "%dddd", GetCalendarInfo(#CAL_SDAYNAME1 + DayOfWeek(date) - 1))
mask = ReplaceString(mask, "%mmmm", GetCalendarInfo(#CAL_SMONTHNAME1 + Month(date) - 1))
mask = ReplaceString(mask, "%ddd", GetCalendarInfo(#CAL_SABBREVDAYNAME1 + DayOfWeek(date) - 1))
mask = ReplaceString(mask, "%mmm", GetCalendarInfo(#CAL_SABBREVMONTHNAME1 + Month(date) - 1))
ProcedureReturn FormatDate(mask, date)
EndProcedure
Debug FormatDate2("%ddd %dd %mmm %yyyy %hh:%ii:%ss", Date())
Debug FormatDate2("%dddd %dd %mmmm %yyyy %hh:%ii:%ss", Date())