Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i m working on project with c# and sql server 2008.
I get the date from datePicker and save it as datePicker1.SelectedDate.ToString()
in sql table where Date column has datatype Date.
Now when i retrive this date from table and display on textBox the Date+Time will be display like this 5/13/2013 12:00:00 AM.

I want to display only date part in textBox like 5/13/2013 .
How Can i do this????
Posted
Updated 16-Jun-13 4:31am
v3

It's not the SQL part that is the problem - you return the value from SQL into the appropriate .NET class: DateTime - so the time part is automatically set to 0, or midnight. DateTime always contains a time element (since it is a number of milliseconds since an arbitrary point in the past).

So what you need to do is stop using the default ToString implementation to display your date value as it always include the time.
C#
myTextBox.Text = myDateTime.ToString("MM/dd/yyyy");
Will do it, or look at this:
Formatting a DateTime for display - format string description[^]
 
Share this answer
 
Comments
Pheonyx 17-Jun-13 8:50am    
My +5
SQL
Use
DateTime.ToShortDateString()
 
Share this answer
 
you can try like this also

SQL
SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS
[DD/MM/YYYY]
 
Share this answer
 
Use This Query.

Select Convert(Datetime,Convert(Varchar,GetDate(),106))
 
Share this answer
 
Hi,
You can do this use Sql script,like 'Convert(Datetime,Convert(Varchar,GetDate(),106))',and if you want to do this in you project,you can do it like 'DateTime.ToShortDateString()',or sting.Substring().

Gook luck.
 
Share this answer
 
1. Convert(Datetime,Convert(Varchar,GetDate(),106))

2. DateTime.ToShortDateString()

3.DateTime.ToString("MM/dd/yyyy")
 
Share this answer
 
select convert(varchar(20),getdate(),101) as "Today Date"
 
Share this answer
 
v2
Hi,

Use this query in sql server :
select convert(varchar(10), getdate(),103)
 
Share this answer
 
To convert that in sql query
SELECT CONVERT(VARCHAR(10), GETDATE(), 110) - MM/dd/YYYY
(or)
To convert in C#
TextBox.Text = DateTime.ToString("MM/dd/yyyy")
 
Share this answer
 
if you want only date try this

SQL
SELECT CONVERT(VARCHAR(10), GETDATE(), 106) AS
date
 
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