Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have declared a field as datetime in sql but i want only time to be inserted as hh:mm format how to do this.
the field is datetime so it is asking for the conversion when i convert the format it is again inserting the date and time
plz help me..
Posted

I guess you need to change the column to varchar() so that you can insert in hh:MM format
 
Share this answer
 
Check below links:
http://www.csharp-examples.net/string-format-datetime/[^]
Easy String to DateTime, DateTime to String and Formatting[^]
http://stackoverflow.com/questions/1398108/how-do-i-format-a-datetime-in-c[^]

For your requirement, I think below code should work:
C#
String.Format("{0:g}", dt);  // "3/9/2008 4:05 PM"  ShortDate+ShortTime
 
Share this answer
 

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