Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Date Time in c#

Date Time in c#

Scheduled Pinned Locked Moved C#
helpquestioncsharp
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajesh_K_Sharma
    wrote on last edited by
    #1

    Hello Friends, I am facing some problem in Date Time in c#. I wrote program like this string strdt= "06/19/2006"; //mm/dd/yyyy DateTime dt= Convert.ToDateTime(strdt).ToString("d") ; When I execute this then I get value in dt like "6/19/2006" But, Actually I need value in dt "06/19/2006" in this format. I mean to say Zero with Six. How can I solve this problem? Any help is appreciated Thanks, Rajesh rajesh

    L M E G B 5 Replies Last reply
    0
    • R Rajesh_K_Sharma

      Hello Friends, I am facing some problem in Date Time in c#. I wrote program like this string strdt= "06/19/2006"; //mm/dd/yyyy DateTime dt= Convert.ToDateTime(strdt).ToString("d") ; When I execute this then I get value in dt like "6/19/2006" But, Actually I need value in dt "06/19/2006" in this format. I mean to say Zero with Six. How can I solve this problem? Any help is appreciated Thanks, Rajesh rajesh

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      See this:

      Console.WriteLine(DateTime.Now.ToString("d", DateTimeFormatInfo.InvariantInfo));

      1 Reply Last reply
      0
      • R Rajesh_K_Sharma

        Hello Friends, I am facing some problem in Date Time in c#. I wrote program like this string strdt= "06/19/2006"; //mm/dd/yyyy DateTime dt= Convert.ToDateTime(strdt).ToString("d") ; When I execute this then I get value in dt like "6/19/2006" But, Actually I need value in dt "06/19/2006" in this format. I mean to say Zero with Six. How can I solve this problem? Any help is appreciated Thanks, Rajesh rajesh

        M Offline
        M Offline
        MCSD Gandalf
        wrote on last edited by
        #3

        If you look at the documentation it states that if the day is a single digit it will be returned as a single digit. I would think it doesn't matter how it is stored internally, but how it is displayed. If you want a day to be displayed with a leading zero, use "dd" in the format string. Here is the link from the MS help files: ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconcustomdatetimeformatstrings.htm HTH Gandalf

        1 Reply Last reply
        0
        • R Rajesh_K_Sharma

          Hello Friends, I am facing some problem in Date Time in c#. I wrote program like this string strdt= "06/19/2006"; //mm/dd/yyyy DateTime dt= Convert.ToDateTime(strdt).ToString("d") ; When I execute this then I get value in dt like "6/19/2006" But, Actually I need value in dt "06/19/2006" in this format. I mean to say Zero with Six. How can I solve this problem? Any help is appreciated Thanks, Rajesh rajesh

          E Offline
          E Offline
          engsrini
          wrote on last edited by
          #4

          use string[] str=dt.Date.GetDateTimeFormats('d'); Take whatever the format you want from str array ;)Srini

          1 Reply Last reply
          0
          • R Rajesh_K_Sharma

            Hello Friends, I am facing some problem in Date Time in c#. I wrote program like this string strdt= "06/19/2006"; //mm/dd/yyyy DateTime dt= Convert.ToDateTime(strdt).ToString("d") ; When I execute this then I get value in dt like "6/19/2006" But, Actually I need value in dt "06/19/2006" in this format. I mean to say Zero with Six. How can I solve this problem? Any help is appreciated Thanks, Rajesh rajesh

            G Offline
            G Offline
            Gammaza
            wrote on last edited by
            #5

            I think the ToShortDateString does it automatically. DateTime date = Convert.ToDateTime(strdt).ToShortDateString();

            1 Reply Last reply
            0
            • R Rajesh_K_Sharma

              Hello Friends, I am facing some problem in Date Time in c#. I wrote program like this string strdt= "06/19/2006"; //mm/dd/yyyy DateTime dt= Convert.ToDateTime(strdt).ToString("d") ; When I execute this then I get value in dt like "6/19/2006" But, Actually I need value in dt "06/19/2006" in this format. I mean to say Zero with Six. How can I solve this problem? Any help is appreciated Thanks, Rajesh rajesh

              B Offline
              B Offline
              BoneSoft
              wrote on last edited by
              #6

              DateTime dt = DateTime.Parse(strdt);
              Console.WriteLine(dt.ToString("MM/dd/yyyy"));


              Try code model generation tools at BoneSoft.com.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups