Validar fecha.
Validar fecha.
Hola,
Estoy buscando una función que me permita validar una fecha; me refiero a que el fecha introducida sea correcta.
Así si el valor encontrado es 35/08/2018 pues que me indique que no es una fecha correcta.
Recuerdo de hace años haberla visto pero ahora no la localizo.
Gracias.
Estoy buscando una función que me permita validar una fecha; me refiero a que el fecha introducida sea correcta.
Así si el valor encontrado es 35/08/2018 pues que me indique que no es una fecha correcta.
Recuerdo de hace años haberla visto pero ahora no la localizo.
Gracias.
Un Saludo
Carlos G.
FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
Carlos G.
FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Validar fecha.
Hmm, I don't think you can enter an invalid date into a date variable type. Have to tried that?
Otherwise here is a test. Note that when a character date is converted to a date format date, if it is invalid it will be an empty date (" / / "). It is still a date data type but it is empty.
Otherwise here is a test. Note that when a character date is converted to a date format date, if it is invalid it will be an empty date (" / / "). It is still a date data type but it is empty.
Code: Select all
#include "fivewin.ch"
Function Main()
Local dDate, cDate
Set date BRITISH // DD/MM/YYYY
set epoch to 1980
Set century on
dDate:= ctod("35/08/2018")
cDate:= dtoc(dDate)
msgInfo(dDate,"dDate")
msgInfo( ctod(cDate), "ctod(cDate)" )
if dtoc(dDate) = " / / "
msgInfo("Valid date ", DateValid(dDate) )
endif
Return nil
// Test for valid date
Function DateValid( dDate )
Local lValid:=.t.
if dtoc(dDate) = " / / "
lValid := .f.
endif
Return lValid
// EOF
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Validar fecha.
if Empty( CTOD( cStr ) )
// invalid date
endif
// invalid date
endif
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: Validar fecha.
Thank you very much mr. Bott and mr. Rao
As Mr. Rao says, then this must be correct right?
The point is that I have a date field that must be corrupted and I want to check its validity.
Excuse my English, I'm using Google translate.
As Mr. Rao says, then this must be correct right?
Code: Select all
FUNCTION lIsDateOk( dDate )
Return ( .Not. Empty( CToD( DToC( dDate ) ) ) )
Excuse my English, I'm using Google translate.
Un Saludo
Carlos G.
FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
Carlos G.
FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Validar fecha.
Why not just this?FiveWiDi wrote:Code: Select all
FUNCTION lIsDateOk( dDate ) Return ( .Not. Empty( CToD( DToC( dDate ) ) ) )
Code: Select all
IF EMPTY( dDate )
// error
ENDIF
Re: Validar fecha.
Because I have found a date with value 04/22/ 320Enrico Maria Giordano wrote:Why not just this?FiveWiDi wrote:Code: Select all
FUNCTION lIsDateOk( dDate ) Return ( .Not. Empty( CToD( DToC( dDate ) ) ) )
EMGCode: Select all
IF EMPTY( dDate ) // error ENDIF
Un Saludo
Carlos G.
FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
Carlos G.
FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Validar fecha.
Impossible. A date field can't contain an invalid date and even if the database were corrupted you wouldn't get the invalid date, you will get an empty date.
EMG
EMG
Re: Validar fecha.
Well, maybe.Enrico Maria Giordano wrote:Impossible. A date field can't contain an invalid date and even if the database were corrupted you wouldn't get the invalid date, you will get an empty date.
EMG
Str( Year( oTdbfDomici:DATAFIRM ), 4 ) + "-" + Right( Str( 100 + Month( oTdbfDomici:DATAFIRM ), 3, 0), 2 ) + "-" + Right( Str( 100 + Day( oTdbfDomici:DATAFIRM ), 3, 0), 2 ) = " 320-04-22"
Un Saludo
Carlos G.
FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
Carlos G.
FiveWin 19.06 + Harbour 3.2, BCC 7 Windows 10
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Validar fecha.
ABSOLUTELY CORRECT !!!Enrico Maria Giordano wrote:Impossible. A date field can't contain an invalid date and even if the database were corrupted you wouldn't get the invalid date, you will get an empty date.
EMG
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Validar fecha.
Thank you for the confirmation, Master.
EMG
EMG