|
||
|
|
#1 (permalink) |
|
Forum Expert
|
Hello. I have a DateTime in this format "MM-dd-yyyy HH:mm:ss". What I need is to make it like this "yyyy-MM-dd HH:mm:ss". According to manual I'm trying first to make my datetime to string and then, using ParseExact method, convert it back to DateTime. So it looks like:
Code:
DateTime dt = another_datetime_that_was_assigned_before; string format = "yyyy-MM-dd HH:mm:ss"; string dt_string = dt.ToString(format); DateTime converted_dt = DateTime.ParseExact(dt_string, format, null); // there could be a CultureInfo instead of "null" but I can't figure out how it affects and if I need it at all dt_string = "2006-11-04 15:00:00" // That's actually what I need converted_dt = "04-11-2006 15:00:00" // Like my "another_datetime_ ... " I've also tried to use any cultures instead of null (like "en-US", "ru-RU") but failed. Now I'm completely lost and can't get where my mistake is. Thanks for your help. |
|
|
|
|
|
#4 (permalink) |
|
Forum Expert
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
|
You cant have DateTime in different formats.
Send it in String format (yyyy-MM-dd...) to SQL and it will do the rest for you..
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." |
|
|
|
|
|
#6 (permalink) | |
|
Forum Expert
|
Quote:
In fact, DateTime is stored as a number ( meaning the number of ticks passed since the beginning of the epoch ), the input format is used only to calculate how many ticks to add. The output to the console was only an example, how to produce a formatted string.
__________________
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|