Hi
When I use FormatDate("%yyyy%mm",Date()) I get "202502" if the date was actually Feb 7, 2025. So it would be nice if the ParseDate worked similarly. ParseDate("%yyyy%mm%dd","20250207134505") should return a value equivalent to Feb 7, 2025 at midnight instead it returns -1. Similarly
ParseDate("%yyyy%mm","20250207134505") would return Feb 1 2025 and ParseDate("%yyyy","20250207134505") would return Jan 1 2025.
Simon
ParseDate Suggestion
ParseDate Suggestion
Simon White
dCipher Computing
dCipher Computing
Re: ParseDate Suggestion
Code: Select all
macro pdate(a,b)
ParseDate(a,Left(b,Len(a)-CountString(a,"%")))
EndMacro
s.s="20250207134505"
Debug ParseDate("%yyyy%mm%dd",s)
Debug pdate("%yyyy%mm%dd",s)
Debug FormatDate("%yy/%mm/%dd", pdate("%yyyy%mm%dd",s))
Debug FormatDate("%yy/%mm/%dd", pdate("%yyyy%mm" ,s))
Re: ParseDate Suggestion
You have a special case
Code: Select all
dt$ = "20250207134505"
Debug Left(dt$, 6)
Debug Left(dt$, 4)
Re: ParseDate Suggestion
What do you mean?
Code: Select all
macro pdate(a,b)
ParseDate(a,Left(b,Len(a)-CountString(a,"%")))
EndMacro
s.s="2025---02 07 13 45 05"
Debug ParseDate("%yyyy---%mm",s) ; -1
Debug FormatDate("%yy/%mm/%dd",pdate("%yyyy---%mm",s)) ; 25/02/01


Re: ParseDate Suggestion
Just for (speed and) fun; it's raining here 
Last edit: fixed/improved "shorter case" and protected vars declaration

Code: Select all
Procedure.q Pdate(a.s,b.s)
Protected c=Len(a)-CountString(a,"%"),lb=Len(b) ; <— protected stuff
If lb>c
ProcedureReturn ParseDate(a,Left(b,c))
ElseIf lb<c
Protected i,j,k,l ; <— additional protected stuff
j=Len(a)
for i=1 to j
if Mid(a,i,1)="%"
k+1
Else
l+1
If l=lb
Break
EndIf
EndIf
Next
ProcedureReturn ParseDate(Left(a,lb+k),b)
EndIf
ProcedureReturn ParseDate(a,b)
EndProcedure
s.s="20250207134505"; longer
Debug ParseDate("%yyyy%mm%dd",s) ; error -1
Debug Pdate("%yyyy%mm%dd",s)
Debug FormatDate("%yy/%mm/%dd", Pdate("%yyyy%mm%dd",s))
Debug ""
s="10251122" ; shorter
Debug ParseDate("%dd%yy%mm%hh%ii",s) ; error -1
Debug Pdate("%dd%yy%mm%hh%ii",s)
Debug FormatDate("%yy/%mm/%dd", Pdate("%dd%yy%mm%hh%ii",s))
Last edited by Piero on Tue Jul 08, 2025 4:49 pm, edited 1 time in total.
Pdate ParseDate UpDated
(see above)