I would like to be able to check whether or not the supplied string is a valid Date format. In looking at the DXL help you would think this is the ideal function: |
Re: Determine whether or not a specified string is a valid Date format
Date GetDate(string in_string)
{ // If the string is a valid Date then convert it to Date
// Otherwise return null
noError()
Date dat = in_string
if (!null lastError()) dat = null
return(dat)
}
void Test(string in_string)
{ Date dat = GetDate(in_string)
print (!null dat) "\t[" in_string "]\t[" dat "]\n"
}
Test("2/14/12")
Test("2/14/12 00:02:30")
Test("02 February 2012")
Test("Alex")
Test("Bob")
Test("02,02,02")
|
Re: Determine whether or not a specified string is a valid Date format llandale - Tue Feb 14 11:12:41 EST 2012
Date GetDate(string in_string)
{ // If the string is a valid Date then convert it to Date
// Otherwise return null
noError()
Date dat = in_string
if (!null lastError()) dat = null
return(dat)
}
void Test(string in_string)
{ Date dat = GetDate(in_string)
print (!null dat) "\t[" in_string "]\t[" dat "]\n"
}
Test("2/14/12")
Test("2/14/12 00:02:30")
Test("02 February 2012")
Test("Alex")
Test("Bob")
Test("02,02,02")
|
Re: Determine whether or not a specified string is a valid Date format DOORSWizard - Tue Feb 14 11:35:32 EST 2012
You can explicitly check for certain locales (1033 -> American) and date formats. I allow myself to modify Louies example. Note that you should explicitly decide which formats are valid, since especially DD/MM/YYYY and MM/DD/YYYY cannot be differentiated in all cases. Regards, Mathias
Date GetDate(string in_string)
{ // If the string is a valid Date then convert it to Date
// Otherwise return null
Date dat = date (in_string, locale 1033, "MM/dd/yy")
if (null dat) dat = date (in_string, locale 1033, "dd MMMM yyyy")
return(dat)
}
void Test(string in_string)
{ Date dat = GetDate(in_string)
print (!null dat) "\t[" in_string "]\t[" dat "]\n"
}
Test("2/14/12")
Test("2/14/12 00:02:30")
Test("02 February 2012")
Test("Alex")
Test("Bob")
Test("02,02,02")
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Determine whether or not a specified string is a valid Date format DOORSWizard - Tue Feb 14 11:35:32 EST 2012 Doh! Sometimes I'm rather blind...
void Test(string in_string)
{ Date dat = date(in_string)
print (!null dat) "\t[" in_string "]\t[" dat "]\n"
}
Test("2/14/12")
Test("2/14/12 00:02:30")
Test("02 February 2012")
Test("Alex")
Test("Bob")
Test("02,02,02")
|