tags:

views:

69

answers:

3

Hi

When I type Textbox1.text = Today,the date is capturing with default time ie 12:00:00,If instead of today if i code Now ,then also same 12:00:00 is capturing in to the sql database.

Textbox1.text= getdate() is getting error.So can any one help to solve this Thank You

A: 

could you tell me clearly what you want to do?

Abhisheks.net
There is a comment section just below the question...
Canavar
+3  A: 

Use:

Textbox1.Text = DateTime.Today.ToShortDateString()

That is equivalent to calling ToString("d") on an instance of a date. You can check out other standard format strings on the DateTime.ToString method MSDN page.

EDIT: the above will address the presentation side of things for the textbox, but your SQL column is probably a DateTime type which will store a default time if not given. That is why you're seeing the "12:00:00 AM" time portion. When you retrieve the data from SQL you should handle it in your ASP.NET code-behind to format the data as shown above.

Is there anything specific you're trying to achieve with just the date portion? On a related note, here's some food for thought: Working with Date and/or Time values in SQL Server: Don't Format, Don't Convert -- just use DATETIME.

Ahmad Mageed
+2  A: 

Try using:

DateTime.Now

i.e.

TextBox1.Text = DateTime.Now.ToString()

HTH! :)

mallows98