Hi!
I have a query that has to return bunch of data based on the calendar
month. I have to make sure that it will return data to me for 28 days
if it is February and for 31 if it is August(for example). I need to
be able to execute it every first of every month for the past 30, 31 or
28 days based on the calendar month. Is there a function or a stored
procedure that I can use to do that?
Thank you,
T. 5 2414
tolcis,
There might be a more elegant way, but this should work:
declare @Now datetime
declare @StartDate datetime
declare @EndDate datetime
set @Now = getdate()
if datepart(d, @Now) = 1 -- only execute if it is the first day of the month
begin
-- to get start date, subtract one month from the date and remove the
time from the date
set @StartDate = convert(varchar(15), dateadd (m, -1, @now), 112)
-- to get end date, remove time from date
set @EndDate = dateadd(m, 1, @StartDate)
print cast(@StartDate as char(25)) + cast(@EndDate as char(25))
-- execute your code here using >= @StartDate and < @EndDate
end
-- Bill
"tolcis" <ny********@gmail.comwrote in message
news:11**********************@11g2000cwr.googlegro ups.com...
Hi!
I have a query that has to return bunch of data based on the calendar
month. I have to make sure that it will return data to me for 28 days
if it is February and for 31 if it is August(for example). I need to
be able to execute it every first of every month for the past 30, 31 or
28 days based on the calendar month. Is there a function or a stored
procedure that I can use to do that?
Thank you,
T.
WHERE create_date < DATEADD(month,DATEDIFF(month, 0,getdate()),0)
AND create_date >= DATEADD(month,DATEDIFF(month, 0,getdate())-1,0)
Roy Harvey
Beacon Falls, CT
On 17 Jan 2007 14:30:29 -0800, "tolcis" <ny********@gmail.comwrote:
>Hi!
I have a query that has to return bunch of data based on the calendar month. I have to make sure that it will return data to me for 28 days if it is February and for 31 if it is August(for example). I need to be able to execute it every first of every month for the past 30, 31 or 28 days based on the calendar month. Is there a function or a stored procedure that I can use to do that?
Thank you, T.
tocis,
Ignore the first post, this is better. Schedule your job to be run on the
first of every month. This will give you the prior month date range for any
date, not just the 1st. This way if the job fails you can also run it on the
2nd, 3rd, etc.
declare @Now datetime
declare @StartDate datetime
declare @EndDate datetime
set @Now = getdate()
-- to get end date, subtract days to get to get 1st of the month for any
date
set @EndDate = dateadd(d, 1 - datepart(d,@Now), @Now)
-- remove the time portion
set @EndDate = convert(char(12), @EndDate, 112)
-- subtract a month for start date
set @StartDate = dateadd(m, -1, @EndDate)
print cast(@StartDate as char(25)) + cast(@EndDate as char(25))
-- execute your code here using >= @StartDate and < @EndDate
-- Bill
"AlterEgo" <al********@dslextreme.comwrote in message
news:12*************@corp.supernews.com...
tolcis,
There might be a more elegant way, but this should work:
declare @Now datetime
declare @StartDate datetime
declare @EndDate datetime
set @Now = getdate()
if datepart(d, @Now) = 1 -- only execute if it is the first day of the
month
begin
-- to get start date, subtract one month from the date and remove the
time from the date
set @StartDate = convert(varchar(15), dateadd (m, -1, @now), 112)
-- to get end date, remove time from date
set @EndDate = dateadd(m, 1, @StartDate)
print cast(@StartDate as char(25)) + cast(@EndDate as char(25))
-- execute your code here using >= @StartDate and < @EndDate
end
-- Bill
"tolcis" <ny********@gmail.comwrote in message
news:11**********************@11g2000cwr.googlegro ups.com...
>Hi!
I have a query that has to return bunch of data based on the calendar month. I have to make sure that it will return data to me for 28 days if it is February and for 31 if it is August(for example). I need to be able to execute it every first of every month for the past 30, 31 or 28 days based on the calendar month. Is there a function or a stored procedure that I can use to do that?
Thank you, T.
Roy,
Wya cool, did not know this!
-- Bill
"Roy Harvey" <ro********@snet.netwrote in message
news:vi********************************@4ax.com...
WHERE create_date < DATEADD(month,DATEDIFF(month, 0,getdate()),0)
AND create_date >= DATEADD(month,DATEDIFF(month, 0,getdate())-1,0)
Roy Harvey
Beacon Falls, CT
On 17 Jan 2007 14:30:29 -0800, "tolcis" <ny********@gmail.comwrote:
>>Hi!
I have a query that has to return bunch of data based on the calendar month. I have to make sure that it will return data to me for 28 days if it is February and for 31 if it is August(for example). I need to be able to execute it every first of every month for the past 30, 31 or 28 days based on the calendar month. Is there a function or a stored procedure that I can use to do that?
Thank you, T.
Thanks. Works great.
Roy Harvey wrote:
WHERE create_date < DATEADD(month,DATEDIFF(month, 0,getdate()),0)
AND create_date >= DATEADD(month,DATEDIFF(month, 0,getdate())-1,0)
Roy Harvey
Beacon Falls, CT
On 17 Jan 2007 14:30:29 -0800, "tolcis" <ny********@gmail.comwrote:
Hi!
I have a query that has to return bunch of data based on the calendar
month. I have to make sure that it will return data to me for 28 days
if it is February and for 31 if it is August(for example). I need to
be able to execute it every first of every month for the past 30, 31 or
28 days based on the calendar month. Is there a function or a stored
procedure that I can use to do that?
Thank you,
T.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: NotGiven |
last post by:
I can get the month of the date selected but not when the claendar control
is first opened or when you go to the next or previous month.
I'm sure it's simple, thanks for any help!
|
by: mathewgk80 |
last post by:
HI all,
I am having popup calendar Javascript code. But i dont know how it is connecting to asp.net code.. I am using asp.net,c#.net and also using 3tier architecture with master page....
I...
|
by: gubbachchi |
last post by:
Hi all,
Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters...
|
by: abhishekbrave |
last post by:
The code below is opening a calendar on mouse over in the same window.
I need the calendar to be opened in new window.
Have to fulfill this requirement urgentely so posting the whole code here.
I...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |