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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. insert only date

insert only date

Scheduled Pinned Locked Moved ASP.NET
database
9 Posts 4 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.
  • M Offline
    M Offline
    m dhu
    wrote on last edited by
    #1

    can we insert only date (mm/dd/yyyy) using smalldatetime(mm/dd/yyyy 00:00:00) as datatype.. into sql table as i used this to select..

    select (CONVERT(CHAR(10), date, 101)) as date

    C N 2 Replies Last reply
    0
    • M m dhu

      can we insert only date (mm/dd/yyyy) using smalldatetime(mm/dd/yyyy 00:00:00) as datatype.. into sql table as i used this to select..

      select (CONVERT(CHAR(10), date, 101)) as date

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can if you want, but it looks to me like you're trying to store it as a string instead of a date. That would be stupid.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      M 1 Reply Last reply
      0
      • C Christian Graus

        You can if you want, but it looks to me like you're trying to store it as a string instead of a date. That would be stupid.

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        M Offline
        M Offline
        m dhu
        wrote on last edited by
        #3

        i tried this

        insert into news(date) values (CONVERT(char(10), 2001-01-01, 101))

        but still it is 2001-01-01 00:00:00

        C 1 Reply Last reply
        0
        • M m dhu

          can we insert only date (mm/dd/yyyy) using smalldatetime(mm/dd/yyyy 00:00:00) as datatype.. into sql table as i used this to select..

          select (CONVERT(CHAR(10), date, 101)) as date

          N Offline
          N Offline
          Nisha Agrawal
          wrote on last edited by
          #4

          If you are using sql server 2008 then there is a data type date for this purpose. you can use that.

          M 1 Reply Last reply
          0
          • M m dhu

            i tried this

            insert into news(date) values (CONVERT(char(10), 2001-01-01, 101))

            but still it is 2001-01-01 00:00:00

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            A datetime has a time component. IF you want to work only with dates, just ignore the time part, and set it to 0:0:0 for all values.

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            1 Reply Last reply
            0
            • N Nisha Agrawal

              If you are using sql server 2008 then there is a data type date for this purpose. you can use that.

              M Offline
              M Offline
              m dhu
              wrote on last edited by
              #6

              im using sql server 2005...

              L 1 Reply Last reply
              0
              • M m dhu

                im using sql server 2005...

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

                madhukk wrote:

                im using sql server 2005...

                It's just the same; like I told you yesterday, store your dates as date values not as strings. Then, when you want to display them or print them you can format them any way you like, in any order, with or without the time.

                M 1 Reply Last reply
                0
                • L Lost User

                  madhukk wrote:

                  im using sql server 2005...

                  It's just the same; like I told you yesterday, store your dates as date values not as strings. Then, when you want to display them or print them you can format them any way you like, in any order, with or without the time.

                  M Offline
                  M Offline
                  m dhu
                  wrote on last edited by
                  #8

                  i stored in date itself but i want seperate into three dropdownlists ddl1(mm) ddl2(dd) ddl3(yyyy)

                  string final = Session["startdate"].ToString();
                  DateTime dt;
                  dt = Convert.ToDateTime(final);
                  final = dt.Day + "/" + dt.Minute + "/" + dt.Year;
                  TextBox1.Text = final;
                  // i got mm/dd/yyyy

                  DropDownList5.SelectedItem.Text = dt.Day.ToString();
                  Object reference not set to an instance of an object.

                  what im i doing wrong????

                  L 1 Reply Last reply
                  0
                  • M m dhu

                    i stored in date itself but i want seperate into three dropdownlists ddl1(mm) ddl2(dd) ddl3(yyyy)

                    string final = Session["startdate"].ToString();
                    DateTime dt;
                    dt = Convert.ToDateTime(final);
                    final = dt.Day + "/" + dt.Minute + "/" + dt.Year;
                    TextBox1.Text = final;
                    // i got mm/dd/yyyy

                    DropDownList5.SelectedItem.Text = dt.Day.ToString();
                    Object reference not set to an instance of an object.

                    what im i doing wrong????

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

                    madhukk wrote:

                    what im i doing wrong????

                    Well your main problem suggests that either DropDownList5 or its SelectedItem property do not have a valid reference. Also you have dt.Minute where you want the month. Lastly, you still seem to be wasting processing on converting DateTime values to and from String values when it is not necessary. I would be tempted to rewrite the above (assuming Session["startdate"] returns a DateTime value) :

                        DateTime dt = Session\["startdate"\];
                        TextBox1.Text = dt.ToString("dd/MM/yy");
                    

                    DropDownList5.SelectedItem.Text = dt.Day.ToString();

                    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