We help IT Professionals succeed at work.

How to retrieve only the date without the time

brgdotnet
brgdotnet asked
on
Medium Priority
219 Views
Last Modified: 2012-05-06
I am reading a date from the database. It has the time appended to the date, because that is how it is stored in SQL server. The problem is that I only want the date portion of the string. Not the hour. How do I do this? Here is an example of the string returned.
2008-10-16 00:00:00.000
TextBox Lmcotangentreason = (TextBox)filterAlchoholMonitoring.FindControl("Lmcotangentreason");
            Lmcotangentreason.Text = Client.cotangent.DateOnProgram.Value.ToString();

Open in new window

Comment
Watch Question

How about this?
ateTime dt = DateTime.Now;
 
string sDate = dt.ToString("dd/MM/yyyy");
 
 *********or**********
 
using System.Globalization;
 
DateTime dt = DateTime.Now;
 
string sDate = dt.ToString("d", new CultureInfo("en-CA"))

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
brgdotnetcontractor

Author

Commented:
Awesome, thanks!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.