How to determine if the date variable is legal

xiaoxiao2021-03-06  22

Reply to: Wingsun (Sun Chunyang) 50 points

Use the following procedure: The return value is an air schedule error. The program can also correct the input formats such as: 1999.9 through the conversion to: 1999-9-91999A9B9 ----------> 1999-9-91999-9 ------- ---> 1999-9-11999 --------------> 1999-1-1 is useful. Ansistring __fastcall formatdate (ANSISTRING TEMPSTR1, TEMPSTR2; INT I, J; if (DateTime == ") {Return";} TempStr2 = DateTime.trim (); if (TempStr2 == ") {Return ""} for (i = 1; i

{

IF ((TempStr2.Substring (i, 1) .ansicompare ("0") <0) || (TempStr2.Substring (i, 1) .ansicompare ("9")> 0))

Break;

}

TempStr1 = Tempstr2.substring (1, i - 1);

IF (i <= tempstr2.length ())

{

For (j = i; j <= TempStr2.Length (); J )

{

IF ((TempStr2.Substring (J, 1) .ansicompare ("0")> = 0) && (Tempstr2.Substring (j, 1) .ansicompare ("9") <= 0))

Break;

}

TempStr2 = Tempstr2.substring (j, tempstr2.length () - j 1);

For (i = 1; i

{

IF ((TempStr2.Substring (i, 1) .ansicompare ("0") <0) || (TempStr2.Substring (i, 1) .ansicompare ("9")> 0))

Break;

}

IF (i == TempStr2.Length ())

{

TempStr2 = TempStr1 "-" TempStr2.Substring (1, 1) "- 01";

}

Else

{

TempStr1 = TempStr1 "-" TempStr2.Substring (1, i-1);

TempStr2 = Tempstr2.substring (i, tempstr2.length () - i 1);

For (i = 1; i

{

IF ((TempStr2.Substring (i, 1) .ansicompare ("0")> = 0) && (TempStr2.Substring (i, 1) .ansicompare ("9") <= 0))

Break;

}

TempStr2 = Tempstr2.substring (i, tempstr2.length () - i 1);

For (i = 1; i <= tempstr2.length (); i )

{

IF ((TempStr2.Substring (i, 1) .ansicompare ("0") <0) || (Tempstr2.Substring (i, 1) .ansicompare ("9")> 0)) Break;

}

TempStr2 = TempStr2.substring (1, i-1);

IF (TempStr2 == "")

TempStr2 = TempStr1 "-1";

Else

TempStr2 = TempStr1 "-" TempStr2;

}

}

Else

{

TempStr2 = TempStr1 "-1-1";

}

Try

{

STRTODATE (TEMPSTR2);

}

Catch (Econverterror & E)

{

MessageBox (NULL, "date format error, please re-enter.", "Date Format Error", MB_OK MB_ICONITION;

TempStr2 = ""

}

Return TempStr2;

}

转载请注明原文地址:https://www.9cbs.com/read-79402.html

New Post(0)