format date time into dd-mm-yy

Posted on 2006-03-26
Last Modified: 2008-03-10
How do i format a date time to a string with the foloowing format

Question by:DaFou
    LVL 48

    Expert Comment


    DateTime d = DateTime.Now;
    string s = d.ToString("MM-dd-yy"));
    LVL 48

    Accepted Solution


    Dim d as DateTime
    Dim s as string

    d = DateTime.Now
    s = d.ToString("MM-dd-yy"))
    LVL 2

    Author Comment

    I have a SQLdatareader with a date in it. Somehoe the conversion fails when i try to use this syntax

    lDR("fld_dt_TransmitDateOut").ToString("dd-MM-yy")      Run-time exception thrown : System.InvalidCastException - Conversion from string "dd-MM-yy" to type 'Integer' is not valid.      
    LVL 48

    Expert Comment

    DateTime structire doesn't hace ToString(Integer) method. This means that lDR("fld_dt_TransmitDateOut") field type is not DateTime in this case. You need to check what is it's type - maybe null.

    Featured Post

    Highfive Gives IT Their Time Back

    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!

    Join & Write a Comment

    IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
    Flash ( has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    755 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

    17 Experts available now in Live!

    Get 1:1 Help Now