FormatDate(Mask$, Date)
Posted: Wed May 18, 2011 4:50 pm
The Mask$ for date formats is really minimal - would be good to have Day and Month names (full and abbreviated).
http://www.purebasic.com
https://www.purebasic.fr/english/
For the mask %month, %day and for the result the userlanguage, should not a big problemfreak wrote:In what language would you prefer the names?
GetLocaleInfo_(#LOCALE_USER_DEFAULT, ...)freak wrote:In what language would you prefer the names?
Code: Select all
Procedure.s FormatDateEx(Mask.s, Date.l)
Protected MonthName.s = Trim(PeekS(?FormatDateEx_MonthName+(Month(Date)-1)*8, 8))
Protected DayOfWeekName.s = Trim(PeekS(?FormatDateEx_DayOfWeekName+DayOfWeek(Date)*9, 9))
Mask = ReplaceString(Mask, "%month", MonthName, #PB_String_NoCase)
Mask = ReplaceString(Mask, "%day", DayOfWeekName, #PB_String_NoCase)
ProcedureReturn FormatDate(Mask, Date)
EndProcedure
Macro FormatDate(Mask, Date)
FormatDateEx(Mask, Date)
EndMacro
DataSection
FormatDateEx_DayOfWeekName:
Data.s "Sunday Monday Tuesday WednesdayThursday Friday Saturday "
FormatDateEx_MonthName:
Data.s "January FebruaryMarch April May June July August SeptemberOctober NovemberDecember"
EndDataSection
Debug FormatDate("%day, %dd. %month %yyyy", Date())
Yeah, you are right. Not having needed it before, I was just surprised to find the function to be so limited. When you only have numbers in dates, people can get confused because of the format. 05/04/2011 is the 5th of April in the UK and other countries, but it's the 4th of May in many others.Little John wrote:It doesn't make sense to build anything and everything into PB. This concerns particularly stuff that we can easily write ourselves by using PB as it is.
Regards, Little John
Sure it does! Fred did it all the time in the past. It's only in the past few years that responding to user requests slowed down, immensely. There was a time when little requests like this one were honored very quickly, but the language was much younger back then, so I guess it had to grow.Little John wrote:It doesn't make sense to build anything and everything into PB.
I absolutely agree, and I'm aware of that problem.IdeasVacuum wrote:When you only have numbers in dates, people can get confused because of the format. 05/04/2011 is the 5th of April in the UK and other countries, but it's the 4th of May in many others.