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. DateTime Problem

DateTime Problem

Scheduled Pinned Locked Moved C#
databasehelpquestion
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.
  • M Offline
    M Offline
    Mohammed Elkholy
    wrote on last edited by
    #1

    Hi I have problem here i have a column DateTime in database i want to insert time only in this column but after i add the time i find the data in table is date with time this conflict the data when i rowfilter the dataview by this column how can i solve it "comment: this is the code of DataView " DV_Deatils.RowFilter = "Room_No='" + combo_Rooms.SelectedValue + "' and ExamDate='" + dtp_examdate.Value.ToString("D") + "'"+ " and ExamTime>='" + txt_time.Text + "' and ExamTimeTo<='"+txt_timeto.Text+"'";

    MD_NADA

    M R V T 4 Replies Last reply
    0
    • M Mohammed Elkholy

      Hi I have problem here i have a column DateTime in database i want to insert time only in this column but after i add the time i find the data in table is date with time this conflict the data when i rowfilter the dataview by this column how can i solve it "comment: this is the code of DataView " DV_Deatils.RowFilter = "Room_No='" + combo_Rooms.SelectedValue + "' and ExamDate='" + dtp_examdate.Value.ToString("D") + "'"+ " and ExamTime>='" + txt_time.Text + "' and ExamTimeTo<='"+txt_timeto.Text+"'";

      MD_NADA

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

      md_nada wrote:

      but after i add the time i find the data in table is date with time

      This is because the fact that SQL doesnt has a datatype called time but DateTime. What you can do is, in the design mode of your database table set the format as short time( or which ever suitable to you):rose:

      C 1 Reply Last reply
      0
      • M Mohammed Elkholy

        Hi I have problem here i have a column DateTime in database i want to insert time only in this column but after i add the time i find the data in table is date with time this conflict the data when i rowfilter the dataview by this column how can i solve it "comment: this is the code of DataView " DV_Deatils.RowFilter = "Room_No='" + combo_Rooms.SelectedValue + "' and ExamDate='" + dtp_examdate.Value.ToString("D") + "'"+ " and ExamTime>='" + txt_time.Text + "' and ExamTimeTo<='"+txt_timeto.Text+"'";

        MD_NADA

        R Offline
        R Offline
        Rhys Gravell
        wrote on last edited by
        #3

        Assuming this is MS Sql Server, there is no Time datatype, only DateTime. You just need to ignore the Date portion of the DateTime field you're interested in.

        Rhys "The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it" They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance." Terry Pratchett

        1 Reply Last reply
        0
        • M Manas Bhardwaj

          md_nada wrote:

          but after i add the time i find the data in table is date with time

          This is because the fact that SQL doesnt has a datatype called time but DateTime. What you can do is, in the design mode of your database table set the format as short time( or which ever suitable to you):rose:

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

          Manas Bhardwaj wrote:

          What you can do is, in the design mode of your database table set the format as short time( or which ever suitable to you)

          The database isn't interested in the format of the DateTime. Setting some format only alters the way it is displayed. It will still store something for the date portion. This means you still have to consider what date you are going to give it so that queries work as expected.


          Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." Ready to Give up - Your help will be much appreciated. My website

          1 Reply Last reply
          0
          • M Mohammed Elkholy

            Hi I have problem here i have a column DateTime in database i want to insert time only in this column but after i add the time i find the data in table is date with time this conflict the data when i rowfilter the dataview by this column how can i solve it "comment: this is the code of DataView " DV_Deatils.RowFilter = "Room_No='" + combo_Rooms.SelectedValue + "' and ExamDate='" + dtp_examdate.Value.ToString("D") + "'"+ " and ExamTime>='" + txt_time.Text + "' and ExamTimeTo<='"+txt_timeto.Text+"'";

            MD_NADA

            V Offline
            V Offline
            Vikram A Punathambekar
            wrote on last edited by
            #5

            Simply ignore the date part when you retrieve the value from the database.

            Cheers, Vıkram.


            After all is said and done, much is said and little is done.

            1 Reply Last reply
            0
            • M Mohammed Elkholy

              Hi I have problem here i have a column DateTime in database i want to insert time only in this column but after i add the time i find the data in table is date with time this conflict the data when i rowfilter the dataview by this column how can i solve it "comment: this is the code of DataView " DV_Deatils.RowFilter = "Room_No='" + combo_Rooms.SelectedValue + "' and ExamDate='" + dtp_examdate.Value.ToString("D") + "'"+ " and ExamTime>='" + txt_time.Text + "' and ExamTimeTo<='"+txt_timeto.Text+"'";

              MD_NADA

              T Offline
              T Offline
              T1TAN
              wrote on last edited by
              #6

              Hi, first of all, I hope you're validating the values of dtp_examdate, txt_time and txt_timeto before filtering your DataView. There are few things you could try, and I'll be honest, I'm not sure if any of them is good. 1. You can place a hardcoded date value in the database, for example '2007-01-01' will always be the date part of your datetime field. Probably not a good idea, you'd still need to handle insert/update properly (by a trigger perhaps), and parse the time value when selected from the DB. I'd say too much overhead. 2. Perhaps better than 1: store the time value in separate tinyint fields, Hour, Minute, Second. I believe this way you can filter the data easily, you only need to combine the values to display the time properly. Hope that helps:doh:

              --- http://sprdsoft.cmar-net.org - We Sprd You Softly Our site features contents and several images. All of this is very weird. In the end, war is not about who's right, it's about who's left.

              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