Tuesday, December 2, 2008

C#: DateTime.ToString()

Looking for simple, direct examples of what the various DateTime conversion functions do which MSDN was completely incapable of providing. Found a great tutorial article that summarized them nicely:
result = theDate.ToString("y");       // result = "January 2007"
SpecifierDescriptionExample
dShort date format. This is equivalent to using ToShortDateString."03/01/2007"
DLong date format. This is equivalent to using ToLongDateString."03 January 2007"
fDate and time using long date and short time format."03 January 2007 21:25"
FDate and time using long date and time format."03 January 2007 21:25:30"
gDate and time using short date and time format."03/01/2007 21:25"
GDate and time using short date and long time format."03/01/2007 21:25:30"
mDay and month only."03 January"
rDate and time in standard Greenwich Mean Time (GMT) format."Wed, 03 Jan 2007 21:25:30 GMT"
sSortable date and time format. The date elements start at the highest magnitude (year) and reduce along the string to the smallest magnitude (seconds)."2007-01-03T21:25:30"
tShort time format. This is equivalent to using ToShortTimeString."21:25"
TLong time format. This is equivalent to using ToLongTimeString."21:25:30"
uShort format, sortable co-ordinated universal time."2007-01-03 21:25:30Z"
ULong format date and time."03 January 2007 17:25:30"
yMonth and year only."January 2007"

Tuesday, February 12, 2008

MSACCESS: Searching for Wildcards

Still end up using Microsoft Access alot when manipulating data. Since it uses the old Microsoft wildcard characters, I often forget how to search for the wildcards themselves. Found a good article that summarizes how to do just that:

Search stringMatch list settingResults
[*]Any Part of FieldReturns all records that contain an asterisk (*). This syntax also works for question marks (?), number signs (#), opening brackets ([), and hyphens (-).
 Whole FieldReturns records that consist only of an asterisk.
 Start of FieldReturns records that start with an asterisk.
*[*]*Any Part of FieldReturns all records that contain an asterisk (*) and any surrounding text. This syntax also works for question marks (?), number signs (#), opening brackets ([), and hyphens (-).
 Whole FieldSame result.
 Start of FieldSame result.
[!*]Any Part of FieldReturns all records that do not contain an asterisk. Keep in mind that this search pattern can return every letter of every word in a record when you use this setting in the Match list. This syntax also works for question marks (?), number signs (#), opening brackets ([), and hyphens (-).

Note  The search string *[!*]* will return records that contain asterisks because it finds all the text that surrounds the asterisk.

 Whole FieldReturns no results at all.
 Start of FieldReturns the first letter of any record that does not contain an asterisk.
ma*[ch]Any Part of FieldReturns all records that contain "ma" and either "c" or "h". For example, this string returns "march" and "match", and it also returns "math" and "manic".
 Whole FieldReturns all records that start with "ma" and end with either "c" or "h". For example, this string returns "march" and "match", and it also returns "math" and "manic".
 Start of FieldReturns all records that start with "ma" and contain "c" or "h".
ma*[!ch]Any Part of FieldHighlights the letters "m" and "a" and all text that follows those letters until it encounters a "c" or an "h". The following figures illustrate this.

| March |

| Match |

In other words, even though you're trying to exclude records that contain "c" and "h", you may see those records because Any Part of Field matches the text that precedes the brackets.

 Whole FieldReturns all records that do not contain a "c" or an "h" if those records end in "c" or "h". For example, the find operation does not return "manic" because the word ends with a "c", but it does return "maniacal" because characters follow the "c".
 Start of FieldReturns those records that start with "ma". Again, Access matches any text that precedes the characters enclosed in brackets, so you may see unwanted results.