Im using a webservice that needs a datetime in the following format "2010-12-24"
I have the string to parse in the same "way" but as said, its a String.
string myDate = "2010-12-24";
How can i parse it so that it gets the same format?
Have tried using : DateTime.Parse(mystring);
but this gives me a colon separated format.
Use DateTime.ParseExact
, providing a custom format string:
DateTime.ParseExact(mystring, "yyyy-MM-dd", CultureInfo.InvariantCulture)
This will throw an exception if the input string cannot be parsed - you may want to use DateTime.TryParseExact
which will return true if successful.
You can use
ToString( formatString )
Eg:- dateTimeObj.ToString( "yyyy-MM-dd" );
Where dateTimeObj is your DateTime object
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