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