开发者

simple way to select all record that are between two date

开发者 https://www.devze.com 2023-04-11 16:29 出处:网络
are there a simple way to select all record that are between two date. should i use datetime for filed type or i can use string type too. something like this :

are there a simple way to select all record that are between two date. should i use datetime for filed type or i can use string type too. something like this :

SELECT * FROM users WHERE datetime_update      is between date1 and date2
  • i use string filed type for some reasons so that would be better.

i try this command in my c# project but it return noting. where am i miss understanding ?

SELECT        user_id, sharj_value, datetime_updat开发者_StackOverflowe
FROM            users
WHERE        (user_id = 0653193963) AND (datetime BETWEEN '1390/07/12%' AND '1390/07/14%')

and this is sample of data in table

filed names    user_id    sharj_value      datetime_update

             0653193963      60000       1390/7/12 08:00:15  
             0653193963      40000       1390/7/13 08:18:44 
             0653193963      40000       1390/7/13 08:20:35

it suppose to return two last row i think.


Try this..

SELECT user_id, sharj_value, datetime
  FROM users
 WHERE user_id = 0653193963 AND datetime BETWEEN '1390/07/12 00:00:00' AND '1390/07/14 23:59:59')


For SQL Server, this T-SQL syntax should work:

SELECT user_id, sharj_value, [datetime]
FROM users
WHERE user_id = 06531939630 AND [datetime] BETWEEN '1390-07-12' AND '1390-07-14'

Note, too, that some locales have year-month-day (like America), and others use year-day-month.

You might also want to look at SQL-Server's "set dateformat"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号