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. How to format a datetime to display day of week and date?

How to format a datetime to display day of week and date?

Scheduled Pinned Locked Moved C#
csharptutorialquestion
6 Posts 5 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.
  • G Offline
    G Offline
    Goalie35
    wrote on last edited by
    #1

    I'm trying to display a date in a c# ms excel report (via the office object library dll) to display as the following (including the commas): Wednesday, May 4, 2011 I've tried several attempts but no luck so far. What's the format I should be using to display a c# datetime correctly? Thanks.

    L D P L G 5 Replies Last reply
    0
    • G Goalie35

      I'm trying to display a date in a c# ms excel report (via the office object library dll) to display as the following (including the commas): Wednesday, May 4, 2011 I've tried several attempts but no luck so far. What's the format I should be using to display a c# datetime correctly? Thanks.

      D Offline
      D Offline
      dbrenth
      wrote on last edited by
      #2

      This is a C# forum so the answer from here would be DateTime.Now.ToString("dddd, MMMM d, yyyy") If this is different from what works in excel, you may need to ask in a different forum.

      Brent

      1 Reply Last reply
      0
      • G Goalie35

        I'm trying to display a date in a c# ms excel report (via the office object library dll) to display as the following (including the commas): Wednesday, May 4, 2011 I've tried several attempts but no luck so far. What's the format I should be using to display a c# datetime correctly? Thanks.

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        You can format DateTime strings in .NET any way you want. This little article[^] of mine contains the necessary links to MSDN, and more. :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        1 Reply Last reply
        0
        • G Goalie35

          I'm trying to display a date in a c# ms excel report (via the office object library dll) to display as the following (including the commas): Wednesday, May 4, 2011 I've tried several attempts but no luck so far. What's the format I should be using to display a c# datetime correctly? Thanks.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Or maybe use the long date time option.

          1 Reply Last reply
          0
          • G Goalie35

            I'm trying to display a date in a c# ms excel report (via the office object library dll) to display as the following (including the commas): Wednesday, May 4, 2011 I've tried several attempts but no luck so far. What's the format I should be using to display a c# datetime correctly? Thanks.

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

            If you mean that you want it formatted by Excel then you have to add the formatting to the cell that holds the datetime value.

            The best things in life are not things.

            1 Reply Last reply
            0
            • G Goalie35

              I'm trying to display a date in a c# ms excel report (via the office object library dll) to display as the following (including the commas): Wednesday, May 4, 2011 I've tried several attempts but no luck so far. What's the format I should be using to display a c# datetime correctly? Thanks.

              G Offline
              G Offline
              Goalie35
              wrote on last edited by
              #6

              Thanks for the help. My solution kept unfortunately having issues using the above formats within my excel report however when I placed a comma in front of the date, it worked fine. String reportDate = "'" + DateTime.Now.ToString("dddd, MMMM d, yyyy"); Thanks.

              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