user682417
user682417

Reputation: 1518

date time showing month value zero

hi I am using mysql as a database it will accept date format like this (yyyy-mm-dd) when the user enter in the text box in any format it will accept only format listed above. I have tried this one by using below code

string dob = tbDob.Text;
DateTime dv = DateTime.Parse(dob);
string format = dv.ToString("yyyy-mm-dd");

but it will showing the month as zero

input :19-08-1908

output:1908-00-19

would any one solve this pls...

Upvotes: 6

Views: 4583

Answers (2)

Bibhu
Bibhu

Reputation: 4081

You are formatting the string according to "yyyy-mm-dd". But you are giving input in the format

input :19-08-1908

so it taking year as 1908, ie its combining 19 and 08 and its taking month as 00 and date as 19 (19 out of 1908).

Change the input format to yyyy-mm-dd, instead, to get the correct output.

Upvotes: 1

VoteyDisciple
VoteyDisciple

Reputation: 37803

mm is for minutes; MM is for month.

Try dv.ToString("yyyy-MM-dd")

If that's not the format you had in mind, try:

  • M: Numeric month (no leading zero)
  • MM: Numeric month (with leading zero)
  • MMM: Abbreviated month name (e.g., "Jan")
  • MMMM: Full month name (e.g., "January")

Upvotes: 12

Related Questions