| |

VerySource

 Forgot password?
 Register
Search
View: 1522|Reply: 11

How does SQL Server query data between two dates?

[Copy link]

2

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-1 06:00:02
| Show all posts |Read mode
If you want to query the data from the 29th of last month to the 28th of this month, how should you write search conditions?
Reply

Use magic Report

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-3-12 10:30:01
| Show all posts
select * from ta where date bewteen '2016-12-29 00: 00: 00'and' 2017-01-28 23:59:59 '
Reply

Use magic Report

0

Threads

34

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-3-12 10:45:01
| Show all posts
where date> = 29th of last month and date <= 28th of this month? ?
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-3-12 12:30:02
| Show all posts
where date field> = '2016-09-29' AND date field <'2016-10-29'
The field is a date type, it is recommended to use> =\<
Reply

Use magic Report

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-3-12 14:00:02
| Show all posts
Well, I think all the upstairs are positive solutions, unless the landlord has other ideas
Reply

Use magic Report

0

Threads

100

Posts

53.00

Credits

Newbie

Rank: 1

Credits
53.00

 China

Post time: 2020-3-12 15:15:02
| Show all posts
select * from table where datefield> = cast (convert (char (8), dateadd (m, -1, getdate ()), 120) + '29' as datetime) and datefield <= cast (convert (char (8) , getdate (), 120) + '28' as datetime);
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-12 16:30:01
| Show all posts
where datecolumn between '2002-10-29' and '2003-11-29'
The general meaning is the above. Maybe the data types do not match well. Let me adjust it myself.
Reply

Use magic Report

1

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-3-13 03:15:01
| Show all posts
Upstairs are all positive solutions
Reply

Use magic Report

2

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-3-14 12:30:01
| Show all posts
The correct solution upstairs, the month is not certain, it is the current month. Sorry for not saying clearly. Just run away, huh, huh.
If there is a solution for New Year's Eve? January this year and December last year
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-3-14 14:45:02
| Show all posts
--try

select * from tbName
where colName> = dateadd (month, -1, convert (char (8), getdate (), 120) + '29')
and colName <convert (char (8), getdate (), 120) + '29'
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list