Reputation: 463
I have variable of a type DateTime objApplicationSummaryInfo.AdmissionDate
. I am trying to assign a value, such as
objApplicationSummaryInfo.AdmissionDate = DateTime.ParseExact(
TextBox3.Text.ToString(), "dd/mm/yyyy", null);
But when i am assigning a value like 27/09/2012
to a textbox3
, the variable objApplicationSummaryInfo.AdmissionDate
takes a value 1/27/2012 12:00:09
. The format as well as the date comes back incorrect.
What possible code am I missing and what can be an alternate solution. Thanks for assistance.
Upvotes: 1
Views: 558
Reputation: 881
hey are you Testing on localHost try it on Server i will work on server but not on localhots
Upvotes: 0
Reputation: 137158
mm
is minutes.
MM
is months
Custom Date and Time Format Strings
Your code should be:
objApplicationSummaryInfo.AdmissionDate = DateTime.ParseExact(
TextBox3.Text.ToString(), "dd/MM/yyyy", null);
You will also need to set the culture:
CultureInfo provider = CultureInfo.InvariantCulture;
objApplicationSummaryInfo.AdmissionDate = DateTime.ParseExact(
TextBox3.Text.ToString(), "dd/MM/yyyy", culture);
Otherwise it will use the culture of the machine running the code.
Upvotes: 2
Reputation: 28990
You can try with - dd/MM/yyyy
DateTime.ParseExact(TextBox3.Text.ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
Upvotes: 1
Reputation: 499132
"dd/mm/yyyy"
should probably be "dd/MM/yyyy"
mm
- is for minutesMM
- is for monthsobjApplicationSummaryInfo.AdmissionDate = DateTime.ParseExact(
TextBox3.Text.ToString(), "dd/MM/yyyy", null);
Upvotes: 1