Link to home
Start Free TrialLog in
Avatar of russomr
russomr

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of daniel_balla
daniel_balla

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or try this:

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

AW
Avatar of daniel_balla
daniel_balla

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.