[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • 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.
0
russomr
Asked:
russomr
  • 2
1 Solution
 
daniel_ballaCommented:
try a cast.
something like:
((DateTime)dr["EstCompletionDate"]).ToShortDateString();

0
 
Arthur_WoodCommented:
or try this:

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

AW
0
 
daniel_ballaCommented:
Arthur_Wood,
> 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.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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