Is my usage of uCharToVal() wrong?
Code: Select all
#include "fivewin.ch"
proc main()
set century on
set date british
? uCharToVal("01/01/2020", "D")
return
Compiled with Harbour+FWH1912
TIA
Code: Select all
#include "fivewin.ch"
proc main()
set century on
set date british
? uCharToVal("01/01/2020", "D")
return
Code: Select all
static function dCharToDate( cDate )
local cFormat, cc, cfmt
local dDate
if ( cc := Upper( cDate ) ) != Lower( cDate )
return dAlphaToDate( cc )
endif
if Len( cDate ) >= 8 .and. IsDigit( SubStr( cDate, 3 ) ) .and. IsDigit( SubStr( cDate, 5 ) ) .and. ;
! Empty( dDate := SToD( Left( cDate, 8 ) ) )
return dDate
endif
if Len( cDate ) >= 10 .and. IsDigit( SubStr( cDate, 3 ) ) .and. !IsDigit( SubStr( cDate, 5 ) ) .and. ;
!IsDigit( SubStr( cDate, 8 ) ) .and. ;
! Empty( dDate := StoD( Left( cDate, 4 ) + SubStr( cDate, 6, 2 ) + SubStr( cDate, 9, 2 ) ) )
return dDate
endif
// check for single digit date/month
if !IsDigit( SubStr( cDate, 2 ) )
cDate := "0" + cDate
endif
if !IsDigit( SubStr( cDate, 5 ) )
cDate := Left( cDate, 3 ) + "0" + SubStr( cDate, 4 )
endif
//
cFormat := Lower( Set( _SET_DATEFORMAT ) )
dDate := CToD( cDate )
if Empty( dDate )
cc := Left( cFormat, 2 )
for each cFmt in { "dd/mm/yy", "mm/dd/yy", "yy/mm/dd" }
if !( Left( cFmt, 2 ) == cc )
SET( _SET_DATEFORMAT, cFmt )
if !Empty( dDate := CTOD( cDate ) )
EXIT
endif
endif
next
endif
Set( _SET_DATEFORMAT, cFormat )
return dDate