开发者

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 accep开发者_运维知识库t 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...


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")


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜