Page 1 of 1

Date Parser / Formater / Checker

Posted: Thu Nov 27, 2003 10:14 pm
by Num3
ERh... Just a procedure i made to check out dates...

Could be useful to someone:

Code: Select all

Procedure.s _fdate(date.s)

  ; date: (day-month-year)
  
  For a = 1 To Len(date) 
    If Mid(date,a,1)="/"
     _date.s + "-"
    ElseIf Mid(date,a,1)="\"
    _date.s + "-"
    ElseIf Mid(date,a,1)="-"
    _date.s + "-"
    ElseIf Mid(date,a,1)="."
      _date.s + "-"
    ElseIf Mid(date,a,1)=>"0" And Mid(date,a,1)<="9"
      _date.s + Mid(date,a,1)
    EndIf  
  Next
   
    xa=FindString(_date,"-",1)
    day.s + Mid(_date,1,xa-1) 

    day.s=Str(Val(day))
    
    If Val(day.s)>31
      ProcedureReturn "ED"
    EndIf
    
    xb=FindString(_date,"-",xa+1)
    
    month.s + Mid(_date,xa+1,xb-xa-1)    

    month.s=Str(Val(month))
    
    If Val(month.s)>12
      ProcedureReturn "EM"
    EndIf

    year.s + Mid(_date,xb+1,Len(_date)) 
    
    If Val(year.s) <60
      year.s =Str(Val(year)+2000)
    ElseIf Val(year.s) >59 And Val(year.s)<100
      year.s =Str(Val(year)+1900)
    EndIf
    
    If Val(year.s)<1960 Or Val(year.s)>2060
      ProcedureReturn "EY"
    EndIf    
  
    If Len(day.s) = 1 : day.s = "0"+day.s:EndIf
    If Len(month.s) = 1 : month.s = "0"+month.s:EndIf

    If ParseDate("%dd-%mm-%yyyy", date) 
      ProcedureReturn day + "-" + month + "-" + year    
    Else
     ProcedureReturn "ID" 
    EndIf

EndProcedure

date.s= _fdate("1-12-2033")


If date="ED"
  MessageRequester( "Error", "The day of the date is incorrect")
  ;Repeat date
ElseIf date="EM"
  MessageRequester( "Error", "The month of the date is incorrect")
  ;Repeat date
ElseIf date="EY"
  MessageRequester( "Error", "The year of the date is not between 1960 and 2060 !")
  ;Repeat date
EndIf


Debug date

Re: Date Parser / Formater / Checker

Posted: Fri Nov 28, 2003 4:33 am
by PB
> Just a procedure i made to check out dates...

See also: viewtopic.php?t=3746

(I really should update my tip to use % instead of the Mod() procedure).