GetDate() function increment with +/- days as Integer
Posted on 2006-07-19
I have a program that needs to have records land in a certain column based of off a date. The value is stored in a SQL database as:
By using today's date withe the GetDate() function in my SQL select statement, it looks like this.
where due_date between GetDate()+34 and GetDate()+42
I've come to manually counting out the days and +34 equates to Aug 22 while +42 equates to Aug 30 according to my math.
So, with between I would want this to show me records with Aug 23 thru Aug 29 due dates.
This bucket (+34 thru +42) does show the record from Aug 23 = Good!
What I can't figure out is why previous bucket (between GetDate()+27 and GetDate()+35) also shows this record??
According to my calculation, +27 would be Aug 15 and +35 days would be Aug 23.
Add the between logic and seems to me it should show records for Aug 16 thru Aug 22.
I'm thinking this may have to do with hours, minutes, seconds from the date field in the sql database and that falling in bucket for earlier than getdate() function run at the time of script(now for instance).
Any thoughts would be appreciated.