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. Database & SysAdmin
  3. Database
  4. How do I change the date format?

How do I change the date format?

Scheduled Pinned Locked Moved Database
databasequestioncsharpdotnet
2 Posts 2 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.
  • D Offline
    D Offline
    davidstern100
    wrote on last edited by
    #1

    In C#, the date in DateTime uses slashes ("/"). Sql uses -'s. How do I change the format in order to save dates (like DateTime.Now) in my sql database?

    David Stern Online!

    C 1 Reply Last reply
    0
    • D davidstern100

      In C#, the date in DateTime uses slashes ("/"). Sql uses -'s. How do I change the format in order to save dates (like DateTime.Now) in my sql database?

      David Stern Online!

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      davidstern100 wrote:

      In C#, the date in DateTime uses slashes ("/").

      It depends on your locale. A DateTime does not store dates with slashes. That is only how they are rendered in your locale.

      davidstern100 wrote:

      How do I change the format in order to save dates (like DateTime.Now) in my sql database?

      Dates are stored as SMALLDATETIME or DATETIME types, not in any specific format with dashes, slashes or whatever. It is the responsibility of the presentation layer to render the dates in a human readable form. If you are attempting to inject a date into a SQL statement in order to make up something like this: INSERT MyTable(SomeDate) VALUES ('2006-01-28') then I suggest you don't. Use Parameterised queries instead. If you tell us exactly why (in other words, to what higher purpose) you want to convert dates in this way we may be able to suggest a better solution.


      Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

      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