How to take only database ?
i want to take only date in one table in sql server 2005 db.for that when we select datetime as datatype it show it's default time also so what can i do for show only date . & if i want to show the current time (System time ) with date instead of default time what can i do?

Amruta Kirdat72 reputationPosted Mar 27, 2011, 11:13 PM EDT
Soft CornerRank #1,221 · 1.5K reputationPosted Mar 27, 2011, 11:45 PM EDT
1. If binding data thro' SqlDataSource then in
Use DataFormatString = "{0:d}" , its a format pattern for GridView to display Short date
2. if Binding thro' SqlDataAdapter then in query Use
CONVERT(VARCHAR(30),ColumnName,111) , it will return date part from datetime
3. For displaying Date only from current Time
DateTime time = DateTime.Now;
Response.Write(time.ToShortDateString());
Soft CornerRank #1,221 · 1.5K reputationPosted Mar 28, 2011, 12:03 AM EDT
as per your question, when your inserting/selecting date only from datetime Use CONVERT(VARCHAR(30),ColumnName/Value,111)
and for current datetime , select convert(varchar, getdate(), 1)
shree gunjal59 reputationPosted Mar 28, 2011, 2:51 AM EDT
i am taking date from user into my form,
according to system time , can it save current time along with the entering date into database .
Suthish NairRank #92 · 22.8K reputationPosted Mar 28, 2011, 3:17 AM EDT
select CONVERT(VARCHAR,column name,101) + ' ' + CONVERT(VARCHAR,SYSDATETIME(),108)
Soft CornerRank #1,221 · 1.5K reputationPosted Mar 28, 2011, 4:37 AM EDT
As per your requirement, you want to insert User Entered Date along with System Current time then try this :
DateTime time = DateTime.Now;
string FormatedDate = "11/02/11"+" "+time.ToLongTimeString(); //here replace your date which is entered by user
DateTime date = DateTime.Parse(FormatedDate);
and finally insert date obj into database, for e.g :
string query = "insert into TableName values('" + date + "')";