Date Calculations  
Author Message
peterpeter





PostPosted: Mon Feb 07 09:58:23 CST 2005 Top

SQL Server Developer >> Date Calculations

Hi Everyone,
I have got a problem with date calculation. I have a
procedure that all me to insert date into a Table based on user input. The
input is a Event Date and Reminder
Example: if the user Enter an Event Date and choose to a reminder for a
certain event... I need to calculate a date that will be a week prior to the
event date as the reminder
My question is how do I calculate prior week of a certain Date..
e.g Event Date = 01/14/2005 I want the reminder to be calculate has
Reminder=01/07/2005

Please help...

ROO

SQL Server208  
 
 
IMOtter





PostPosted: Mon Feb 07 09:58:23 CST 2005 Top

SQL Server Developer >> Date Calculations Try this: dateadd(w,-1,event_date)

 
 
IMOtter





PostPosted: Mon Feb 07 10:00:54 CST 2005 Top

SQL Server Developer >> Date Calculations sorry abou the previous. Should be dateadd(ww,-1,event_date)

 
 
Bob





PostPosted: Mon Feb 07 10:05:50 CST 2005 Top

SQL Server Developer >> Date Calculations
> Hi Everyone,
> I have got a problem with date calculation. I
> have a procedure that all me to insert date into a Table based on
> user input. The input is a Event Date and Reminder
> Example: if the user Enter an Event Date and choose to a reminder
> for a certain event... I need to calculate a date that will be a week
> prior to the event date as the reminder
> My question is how do I calculate prior week of a certain Date..
> e.g Event Date = 01/14/2005 I want the reminder to be calculate
> has Reminder=01/07/2005
>
> Please help...
>
> ROO
It's a lot easier to help if you provide DDL and sample data in the form of
insert statements (www.aspfaq.com/5006). As it now stands, I have to guess
at the data type and name of the "Event Date" column. Here is my solution
based on the guess that it is a datetime column (you should look up Using
Date and Time Data in SQL Books Online). This is an example using variables.
You should be able to convert it to a select statement if it is relevant to
your situation:





Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
 
Roplab





PostPosted: Mon Feb 07 10:35:40 CST 2005 Top

SQL Server Developer >> Date Calculations Hi Everyone,
I have got a problem with date calculation. I have a procedure that all
me to insert date into a Table based on user input. The input is a Event
Date and Reminder
Example: if the user Enter an Event Date and choose to a reminder for a
certain event... I need to calculate a date that will be a week prior to the
event date as the reminder
My question is how do I calculate prior week of a certain Date.. e.g Event
Date = 01/14/2005 I want the reminder to be calculate has
Reminder=01/07/2005
Below is my procedure:

CREATE PROCEDURE EventReminder
@DocketID int,
@EventName varchar(50),
@Reminder int,
@EventNumber int,
@EventDate varchar(50)

AS
---Declare variables





---Initialize the Variables





---Delete the Reminder if the DocketID already exist


---Start the loop

Begin ---Start Begin


----Weekly Reminder

begin

@EventReminderNum
begin
---Increment of the week

@EventReminderNum + 1


insert into Reminder
(DocketID, EventDate, EventName, Reminder)
Values


end
end

--print 'The counter is ' +


end ----End Begin
GO




> > Hi Everyone,
> > I have got a problem with date calculation. I
> > have a procedure that all me to insert date into a Table based on
> > user input. The input is a Event Date and Reminder
> > Example: if the user Enter an Event Date and choose to a reminder
> > for a certain event... I need to calculate a date that will be a week
> > prior to the event date as the reminder
> > My question is how do I calculate prior week of a certain Date..
> > e.g Event Date = 01/14/2005 I want the reminder to be calculate
> > has Reminder=01/07/2005
> >
> > Please help...
> >
> > ROO
> It's a lot easier to help if you provide DDL and sample data in the form
of
> insert statements (www.aspfaq.com/5006). As it now stands, I have to guess
> at the data type and name of the "Event Date" column. Here is my solution
> based on the guess that it is a datetime column (you should look up Using
> Date and Time Data in SQL Books Online). This is an example using
variables.
> You should be able to convert it to a select statement if it is relevant
to
> your situation:
>



>
> Bob Barrows
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>