Ashish
Ashish

Reputation: 21

Want to use datetime in yyyy-MM-ddTHH:mm:ss format but its type should be Datetime, is that possible in C#

Actually i am calling one web service's method that accepts date time parameter but in YYYY-MM-DDThh:mm:ss format so Want to use datetime in yyyy-MM-ddTHH:mm:ss format but type should be datetime, is that possible in C#.

Upvotes: 2

Views: 783

Answers (2)

Adil
Adil

Reputation: 148110

Date is not stored in the form of string internally, the format is just a presentation, so you can not force the DateTime object of specific format. You rather convert it to the format you want. You can have DateTime as parameter of web service and convert it to the format you want or you can have string variable that has DateTime of specific format that you would convert to DateTime object using DateTime.ParseExact.

DateTime Values and their string representations

Internally, all DateTime values are represented as the number of ticks (the number of 100-nanosecond intervals) that have elapsed since 12:00:00 midnight, January 1, 0001. The actual DateTime value is independent of the way in which that value appears when displayed in a user interface element or when written to a file. The appearance of a DateTime value is the result of a formatting operation. Formatting is the process of converting a value to its string representation, MSDN.

Upvotes: 3

Raidri
Raidri

Reputation: 17550

Use DateTime objects in your C# code and convert when you communicate with the webservice:

string Format = "yyyy-MM-ddTHH:mm:ss";

// getting data from the webservice
DateTime FromWebservice = DateTime.ParseExact(WebserviceDateTimeString, Format);

// sending data to the webservice
string ForWebservice = CsharpDateTime.ToString(Format);

Upvotes: 0

Related Questions