I am developing an ASP.Net C# web application that should access the database using ODBC then pass the gotten data to a web service.
I face a problem in converting date as I tried using Convert.ToDateTime and parseDate to change the format of the dates acccessed from the database and change it to the suitable formate needed for the web service.
for example:
the database datetime storage format is "MM/dd/yyyy hh:mm:ss tt"
07/15/2011 03:05:10 pm
the webservice datetime storage format is "dd/MM/yyyy hh:mm:ss"
15/07/2011 15:00:00
How I can change and convert these different formats for datetime data types so that the web service accepts it properly?
Also, there is a boolean data type in the web service which is stored as integer in the database, how I can handle that so that the web service accepts the boolean data type in a correct way?
for example:
the isGiven variable may have the value of 0 in database while it should be false or true in the web service as it accepts it as boolean only.
is there an implicit conversion between int and bool data types?
No, it’s not. The database doesn’t store the datetime value as a formatted string, it stores it numerically representing a point in time. When you read it you get it as a
DateTimevalue, not astring.To convert the DateTime value to the format
dd/MM/yyyy hh:mm:ssyou just use a custom format string:Converting an integer to a boolean can either be done when you read it from the database:
or afterwards: