Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have windows service program in which I am accessing database and I have simple query to extract expiry_date and some fields too , But when i run this query in winForms application it gives resulting date into proper format (e.g 01/02/2014) but when same query runs in windows service program it gives improper format (e.g 1/2/2014).
Can anyone tell me what is the reason?

Thanks
Posted

Probably, because you don;t specify a format in the service, so it is using the system default. Dates (and DateTime values) don't have any intrinsic format, they are stored as a number of ticks since since an arbitrary point in time. They only acquire any formatting when they are converted to strings for presentation.

So look at your conversion / presentation code and see what happens there.
 
Share this answer
 
Date is a date[^] and nothing else! It does not have specific format! You can format it using String.Format() or ToString() function.

Please, see:
Standard Date and Time Format Strings[^]
Custom Date and Time Format Strings[^]
 
Share this answer
 
Comments
Member 11543226 27-Aug-15 4:38am    
I also changed my system date format to mm/dd/yyyy but still it gives same error
Maciej Los 27-Aug-15 4:58am    
Seems, you don't get it... Your system date format is not important! The way you display date is very important!
Member 11543226 27-Aug-15 5:13am    
I displayed date in exact format as saved in database I cannot convert it in any custom string format

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900