DateTime a1 = new DateTime(Convert.ToDateTime(txtStartDate.Text).Year, Convert.ToDateTime(txtStartDate.Text).Month, Convert.ToDateTime(txtStartDate.Text).Day, 0, 0, 0);
I have tried to change system time from 12 hrs hh to 24 hours HH and restart web site insert still is 12:00:00
I want 00:00:00
Function usedstrftime() can change the date format in python.
To convert a datetime to a date, you can use the CONVERT() , TRY_CONVERT() , or CAST() function.
On the Home tab, click the Dialog Box Launcher next to Number. You can also press CTRL+1 to open the Format Cells dialog box. In the Category box, click Date or Time, and then choose the number format that is closest in style to the one you want to create.
What you're seeing is a formatting issue rather than a data issue. It really is 00:00:00, but however you're converting it to a string is showing it as 12:00:00, presumably with an implicit "am". Don't forget that a DateTime
doesn't actually have a format in it - it's just the date/time. You can format it appropriately yourself, e.g.
Console.WriteLine(a1.ToString("yyyy-MM-dd HH:mm:ss"));
All this aside, I would strongly recommend that you don't create the DateTime
this way. Personally I prefer to use DateTime.TryParseExact
or DateTime.ParseExact
anyway, rather than using "whatever patterns the current culture happens to prefer", but even if you do want to parse with Convert.ToDateTime
, it would be clearer to do it once, and then use the Date
property to get a DateTime
with the time set to 0:
DateTime a1 = Convert.ToDateTime(txtStartDate.Text).Date;
Well, technically there is no time as 00:00:00. After 11:59:59 it becomes 12:00:00. Maybe I'm just not understanding what you're trying to do :)
You could have special logic in your code that modifies it such that if it is 12:00:00, then display it as 00:00:00 or something. But out of the box there is no magic or format string that will do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With