Y yl0859 Member Dec 11, 2024 #1 "Querying the SQLEXPRESS database by time range" EX: Dim query As String = "SELECT * FROM ALARM WHERE TIME >= '" & daysstart & "' AND TIME <= '" & daysend & "' ORDER BY 报警时间 DESC", i want to ask "What should the format of daysstart and daysend be?"
"Querying the SQLEXPRESS database by time range" EX: Dim query As String = "SELECT * FROM ALARM WHERE TIME >= '" & daysstart & "' AND TIME <= '" & daysend & "' ORDER BY 报警时间 DESC", i want to ask "What should the format of daysstart and daysend be?"
Erel B4X founder Staff member Licensed User Longtime User Dec 11, 2024 #2 1. Never build queries like this. Learn how to use parameterized queries. See point #5: https://www.b4x.com/android/forum/t...ommon-mistakes-and-other-tips.116651/#content 2. You need to find the set date format and match it with DateTime.DateFormat. B4X: SQL.ExecQuery2("SELECT * FROM ALARM WHERE TIME >= ? AND TIME <= ? ORDER BY DESC", Array(DateTime.Date(StartTime), DateTime.Date(EndTime)) Upvote 0
1. Never build queries like this. Learn how to use parameterized queries. See point #5: https://www.b4x.com/android/forum/t...ommon-mistakes-and-other-tips.116651/#content 2. You need to find the set date format and match it with DateTime.DateFormat. B4X: SQL.ExecQuery2("SELECT * FROM ALARM WHERE TIME >= ? AND TIME <= ? ORDER BY DESC", Array(DateTime.Date(StartTime), DateTime.Date(EndTime))
sirjo66 Well-Known Member Licensed User Longtime User Dec 11, 2024 #3 Obviously Erel gave you the correct solution, but also you can try this: B4X: Dim query As String = "SELECT * FROM ALARM WHERE TIME >= '2024-11-22 07:12:00' AND TIME <= '2024-12-11 08:05:30' ORDER BY 报警时间 DESC" So, you can understand by self that the format is 'yyyy-MM-dd HH:mm:ss' (string type) Try it, and then change it into parameterized queries A little question: with "TIME" do you means date and time or only time of a day ?? Upvote 0
Obviously Erel gave you the correct solution, but also you can try this: B4X: Dim query As String = "SELECT * FROM ALARM WHERE TIME >= '2024-11-22 07:12:00' AND TIME <= '2024-12-11 08:05:30' ORDER BY 报警时间 DESC" So, you can understand by self that the format is 'yyyy-MM-dd HH:mm:ss' (string type) Try it, and then change it into parameterized queries A little question: with "TIME" do you means date and time or only time of a day ??