Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Setting ToDate parameter


Setting ToDate parameter

Author
Message
justfillingtime
justfillingtime
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 77
Hi All,

Quick question, I'm looking to set my 'ToDate' parameter to the last day of the month up to 23:59:59 but can't figure it out.

I've got my parameter to set the the final day of the month (using this: =DateSerial(Year(Now()), Month(Now()), "1").AddDays(-1)) but not up to a second before midnight, so infact it is missing out the final day of the months data.

Many thanks.
Jeffrey Williams 3188
Jeffrey Williams 3188
SSCarpal Tunnel
SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)SSCarpal Tunnel (4.5K reputation)

Group: General Forum Members
Points: 4460 Visits: 9818
You really don't want to be building your searches this way. What happens when you change from a datetime data type to a datetime2 data type?

You will then be forced to update your code because now it could be missing data again.

A better way to do your checks is to use this:

WHERE datecolumn >= {start date and time = 00:00:00.000}
AND datecolumn < {end date + 1 and time = 00:00:00.000}

For example:

WHERE datecolumn >= '2013-01-01 00:00:00.000' -- from the first of the year
AND datecolumn < '2013-03-01 00:00:00.000' -- less than March 1st

The above will include everything for January and February - but not include March.

Using BETWEEN or <= requires you to add the time, and as I stated before will require that you update your code if the data type changes.

Jeffrey Williams
Problems are opportunities brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search