Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date time showing month value zero

Tags:

date

c#

datetime

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...

like image 207
user682417 Avatar asked Dec 17 '22 12:12

user682417


2 Answers

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")
like image 154
VoteyDisciple Avatar answered Jan 01 '23 17:01

VoteyDisciple


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.

like image 33
Bibhu Avatar answered Jan 01 '23 18:01

Bibhu