Display date with ToShortDateString()

Posted on 2006-04-25
Last Modified: 2012-06-21
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.
Question by:russomr
    LVL 9

    Accepted Solution

    try a cast.
    something like:

    LVL 44

    Expert Comment

    or try this:

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

    LVL 9

    Expert Comment

    > 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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now