January 13, 2010 at 2:28 am
Hi,
I need to take today's date and time, add 4 weeks to the date then insert it into the date field reminderdate below. I'm not fussed if it's 28, 30 or 31 days every time. I know dates are a pain to work with.
Can someone give me some advice on this. I was trying the following but i can't seem to find the right format. I am using classic ASP so maybe i am better off using vbscript but i am sure it can be done in SQL.
Thanks for any help.
INSERT INTO wce_activity (uniqueid, createdate, reminderdate) VALUES ('"& (uid) &"','"& date() &"','" DATEADD(mm, + 1, GETDATE()) "')
January 13, 2010 at 2:35 am
that should work,
SELECT dateadd(m, 1, getdate())
What is the format that you are looking for?
---------------------------------------------------------------------------------
January 13, 2010 at 2:40 am
Thanks for your reply. I need it like this 13/01/2010 10:00:00
I tried adding your code but i am am getting a syntax error at the begining of the -->SELECT dateadd(m, 1, getdate()) I will keep playing.
Let me know if there is an obvious reason for this error. Thanks again
January 13, 2010 at 3:21 am
This should work:
SELECT convert(varchar,dateadd(m, 1, getdate()),103) + ' ' + convert(varchar,dateadd(m, 1, getdate()),114)
January 13, 2010 at 3:37 am
sc-w (1/13/2010)
INSERT INTO wce_activity (uniqueid, createdate, reminderdate) VALUES ('"& (uid) &"','"& date() &"','" DATEADD(mm, + 1, GETDATE()) "')
Hi,
Try this
INSERT INTO wce_activity (uniqueid, createdate, reminderdate)
select user_id() ,getdate(),dateadd(m, 1, getdate())
or
INSERT INTO wce_activity (uniqueid, createdate, reminderdate)values (user_id() ,getdate(),dateadd(m, 1, getdate()))
January 13, 2010 at 3:49 am
Hi,
I thave added both but when i print them to screen before they are inserted i get the following with no dates. It's just writting the code. Any ideas?
INSERT INTO wce_activity (uniqueid, createdate, reminderdate)select user_id() ,getdate(),dateadd(m, 1, getdate())
INSERT INTO wce_activity (uniqueid, createdate, reminderdate)values (user_id() ,getdate(),dateadd(m, 1, getdate())
January 13, 2010 at 8:19 am
Hello,
I'm not sure I understand what do you mean by when you print them before inserting.
Print what?
The values? All the statement? Or what?
try this:
'INSERT INTO ##tempt (uniqueid, createdate, reminderdate)select'+ cast(user_id() AS varchar)+' ,'+cast(getdate() AS varchar)+','+cast(dateadd(m, 1, getdate()) AS varchar)
Wish you good ideas! 🙂
Andreea
January 13, 2010 at 9:26 am
Thanks for the help. Becuase i was using VBScript i managed to do something in that and got the result i needed.
I know this is a SQL forum and i'll get shouted at but here is what i used in case it helps someone else.
dateplusmonth = DateAdd("m",1,date())
mydate = Year(dateplusmonth) & "/" & Month(dateplusmonth) & "/" & Day(dateplusmonth)
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply