Datetime Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luke Davis

    #1

    Datetime Question

    Is there a way to format the date into an YYYY:MM:DD format?

    Right now January, for example, is equal to 1, instead of 01. Is there a
    way, besides writing a long if/then, of formating all single digit dates to
    prefix a 0?

    So January 1, 2001 would look like 2001-01-01, not 2001-1-1.

    Thanks,

    --
    Luke Davis, MCSE: Security
    DEM Networks - Senior Systems Architect
    7225 N First, Suite 105
    Fresno, CA 93720
    Office: 1 (559) 439-1000
    Fax: 1 (866) 640-2041



  • Tom Porterfield

    #2
    Re: Datetime Question

    Luke Davis wrote:
    Is there a way to format the date into an YYYY:MM:DD format?
    >
    Right now January, for example, is equal to 1, instead of 01. Is there a
    way, besides writing a long if/then, of formating all single digit dates to
    prefix a 0?
    >
    So January 1, 2001 would look like 2001-01-01, not 2001-1-1.
    string formattedDate = DateTime.Now.To String("yyyy-MM-dd");
    --
    Tom Porterfield

    Comment

    • Luke Davis

      #3
      Re: Datetime Question

      That is so simple it's amazing

      thank you



      "Tom Porterfield" <tpporter@mvps. orgwrote in message
      news:u5hDrCOyHH A.4652@TK2MSFTN GP05.phx.gbl...
      Luke Davis wrote:
      >Is there a way to format the date into an YYYY:MM:DD format?
      >>
      >Right now January, for example, is equal to 1, instead of 01. Is there
      >a way, besides writing a long if/then, of formating all single digit
      >dates to prefix a 0?
      >>
      >So January 1, 2001 would look like 2001-01-01, not 2001-1-1.
      >
      string formattedDate = DateTime.Now.To String("yyyy-MM-dd");
      --
      Tom Porterfield

      Comment

      Working...