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. Web Development
  3. ASP.NET
  4. storing datetime in sql from asp.net

storing datetime in sql from asp.net

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasehelpquestion
4 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.
  • L Offline
    L Offline
    Learning IT
    wrote on last edited by
    #1

    i am using datetime control to store datetime in sql,the format which i am using is creating problem in other systems but that was running perfectly in my system,what do i do? in aspx file datetime control is this-: in cs file date is send to sql like this-:

    using System.Globalization;

    IFormatProvider culture = new CultureInfo("fr-FR", true);

    DateTime dt = Convert.ToDateTime((DateTime.Parse((txt_dt.Text).ToString(), culture, DateTimeStyles.NoCurrentDateDefault)).ToString("MM/dd/yyyy"));

    Maniiiiiiiiiiiiiii

    M L 2 Replies Last reply
    0
    • L Learning IT

      i am using datetime control to store datetime in sql,the format which i am using is creating problem in other systems but that was running perfectly in my system,what do i do? in aspx file datetime control is this-: in cs file date is send to sql like this-:

      using System.Globalization;

      IFormatProvider culture = new CultureInfo("fr-FR", true);

      DateTime dt = Convert.ToDateTime((DateTime.Parse((txt_dt.Text).ToString(), culture, DateTimeStyles.NoCurrentDateDefault)).ToString("MM/dd/yyyy"));

      Maniiiiiiiiiiiiiii

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      Use the Invariant culture to store the date...

      Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

      L 1 Reply Last reply
      0
      • M Manas Bhardwaj

        Use the Invariant culture to store the date...

        Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

        L Offline
        L Offline
        Learning IT
        wrote on last edited by
        #3

        How?

        Maniiiiiiiiiiiiiii

        1 Reply Last reply
        0
        • L Learning IT

          i am using datetime control to store datetime in sql,the format which i am using is creating problem in other systems but that was running perfectly in my system,what do i do? in aspx file datetime control is this-: in cs file date is send to sql like this-:

          using System.Globalization;

          IFormatProvider culture = new CultureInfo("fr-FR", true);

          DateTime dt = Convert.ToDateTime((DateTime.Parse((txt_dt.Text).ToString(), culture, DateTimeStyles.NoCurrentDateDefault)).ToString("MM/dd/yyyy"));

          Maniiiiiiiiiiiiiii

          L Offline
          L Offline
          Learning IT
          wrote on last edited by
          #4

          i have found this in some replies but dat was not working. I always use ISO format when typing SQL in Query Analyzer, but for accessing the application through ADO.NET (ASP.NET is for web applications and has nothing to do with the database). I don't worry about the date format as I use parameters. For example SqlCommand cmd = new SqlCommand(); cmd.Connection = myConnection; cmd.CommandText = "SELECT * FROM MyTable "+ "WHERE SomeDate BETWEEN @startDate AND @endDate"; cmd.Parameters.Add("@startDate", theStartDateTimeObject); cmd.Parameters.Add("@endDate", theEndDateTimeObject); SqlDataReader reader = cmd.ExecuteDataReader(); theStartDateTimeObject and theEndDateTimeObject are DateTime objects. If you use these then you don't need to know what format to write the dates in to the SQL String - and nor should you need to convert it. The database should be used for storing information. You shouldn't really be doing any localisation functions with the database as that is all presentation layer stuff.

          Maniiiiiiiiiiiiiii

          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