• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

Display date with ToShortDateString()

I have a datetime field in SQL Server that is being pulled into the datareader.  I'm trying to display it like so:

lblEstCompletionDate.Text = dr["EstCompletionDate"].ToShortDateString();

I'm trying all kinds of things and just can't get it to display in a mm/dd/yyyy format.  I'm not sure why the above does not work.  I'm getting:

'object' does not contain a definition for 'ToShortDateString'

What is the propper way to accomplish what I'm trying?  If it's not ToShortDateString, what is it?

Thanks in advance.
  • 2
1 Solution
try a cast.
something like:

or try this:

lblEstCompletionDate.Text = cDate(dr["EstCompletionDate"]).ToString("mm/dd/yyyy'")

> or try this:

> lblEstCompletionDate.Text = cDate(dr["EstCompletionDate"]).ToString(<wbr/>"mm/dd/yyy<wbr/>y'")

> AW
by the syntax used in the question, I would assume russomr uses C# not VB so the cDate function wouldn't work.
Besides, russomr you can use ToString method to output a certain date format, but then you should use ToString("MM/dd/yyyy") as if you use lowercase m that will output minutes not month.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now