6
Answers

how to take only database ?

Photo of shree gunjal

shree gunjal

14y
1.6k
1
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?

Answers (6)

0
Photo of Soft Corner
NA 3.1k 484.2k 14y
Hi Shree,
  
   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 + "')";
0
Photo of Suthish Nair
NA 31.7k 4.6m 14y

 refer example:

 select CONVERT(VARCHAR,column name,101) + ' ' + CONVERT(VARCHAR,SYSDATETIME(),108)


0
Photo of shree gunjal
NA 77 161.9k 14y
Thanks for Reply .
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 .
0
Photo of Soft Corner
NA 3.1k 484.2k 14y
I think i forget to see the category, if your post is just related with Database concept then,
 
  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)
0
Photo of Soft Corner
NA 3.1k 484.2k 14y
Hi Shree,

    1. If binding data thro' SqlDataSource then in <asp:BoundField
          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());
0
Photo of Amruta Kirdat
NA 128 30.7k 14y
use .ToShortDateTime() with your datetime variable...