string date = Convert.ToString(context.SP_GetDate().FirstOrDefault().UpdateTime);
UpdateTime
is Day/Month/Year in my database however,
When i use above query , update time always displays like below
7.1.2014 00:00:00
How can i get day/month/year ?
Specify a format string when performing the conversion. Don't Convert.ToString
, which doesn't allow for different format strings - call ToString
on the DateTime
. For example:
DateTime updated = context.SP_GetDate().FirstOrDefault().UpdateTime;
string updatedText = updated.ToString("d");
Here, d
is the "short date" standard date/time format specifier. There are others to choose from.
Alternatively, you could specify a custom date/time format, e.g.
DateTime updated = context.SP_GetDate().FirstOrDefault().UpdateTime;
string updatedText = updated.ToString("yyyy-MM-dd");
Note that these will use the "current culture" for localization, picking the language, standard date format, month names etc. You can specify a different culture if you need to - typically the invariant culture, used for machine to machine communication:
DateTime updated = context.SP_GetDate().FirstOrDefault().UpdateTime;
string updatedText = updated.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
See more on this question at Stackoverflow