Page 1 of 1
FORMATDATE - add single digit tokens
Posted: Wed Oct 05, 2022 11:35 pm
by miskox
FORMATDATE () has two digit tokens. We in Slovenia should write dates like this:
There must be a space after the dot and (day and month) numbers should not have a leading zero. Why? Because in a sentence we too write a space after a dot - same rule applies here. Dot is not connected to the letter/number/character on the right.
So maybe
could be added?
Edit: looks like we are not the only one:
https://en.wikipedia.org/wiki/Date_format_by_country
Thanks.
Saso
Re: FORMATDATE - add single digit tokens
Posted: Thu Oct 06, 2022 1:58 am
by Little John
Until that will be built-in into PureBasic, you can use this:
Code: Select all
Procedure.s MyFormatDate (mask$, date.i=-1)
; in : mask$: can contain the same tokens as used with PB's FormatDate(),
; plus the following additional ones:
; - %d --> day number without leading "0"
; - %m --> month number without leading "0"
; date : date value in PB's format; -1 for current system date and time
; out: mask string with all tokens replaced by the respective date values
If date = -1
date = Date()
EndIf
mask$ = FormatDate(mask$, date)
mask$ = ReplaceString(mask$, "%d", Str(Day(date)))
mask$ = ReplaceString(mask$, "%m", Str(Month(date)))
ProcedureReturn mask$
EndProcedure
Debug MyFormatDate("%d. %m. %yyyy")
For even more possibilities, see
FormatDateEx().
Re: FORMATDATE - add single digit tokens
Posted: Thu Oct 06, 2022 4:53 am
by TassyJim
Code: Select all
mydate$ = FormatDate(" %dd. %mm. %yyyy",Date())
mydate$ = ReplaceString(mydate$," 0"," ")
Debug mydate$
; all in one line with leading space removed if present
mydate$ = Trim(ReplaceString(FormatDate(" %dd. %mm. %yyyy",Date())," 0"," "))
Debug mydate$
Re: FORMATDATE - add single digit tokens
Posted: Thu Oct 06, 2022 6:33 am
by miskox
Wow! Thanks. That was fast. Of course native solution would be prefered.
Saso