I think there is no
Date only data type in C#
. Hence, even if
only Date
is required the
DateTime
Type of C# is to be used, which stores both the
Date and Time.
However, the the
DateTime
in
UI controls and reports
can be represented as a
string
in the
required format
using either the
Custom Date and Time Format Strings[
^] or using
Standard Date and Time Format Strings[
^]
The
DateTime
format is influenced by the
CurrentCulture
if a specific culture is not given while parsing from a string and while converting to the string format.
So, if a
Culture
independent conversion is required then
InvariantCulture
can be used as follows.
DateTime today = DateTime.Now;
string todayAsText = today.ToString("dd/MM/yyyy",
System.Globalization.CultureInfo.InvariantCulture);
Console.WriteLine (todayAsText);
DateTime parsedDate = DateTime.ParseExact("14/06/2012","d/M/yyyy",
System.Globalization.CultureInfo.InvariantCulture);
Console.WriteLine (parsedDate.ToString());
So, in the above example, the code
textBox.Text = value.Date.ToString();
value = Convert.ToDateTime(textBox.Text);
can be modified using
DateTimeFormat
as shown in the above example to achieve the effect of
only Date