Insert date plus 4 weeks

  • 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()) "')

  • that should work,

    SELECT dateadd(m, 1, getdate())

    What is the format that you are looking for?

    ---------------------------------------------------------------------------------

  • 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

  • This should work:

    SELECT convert(varchar,dateadd(m, 1, getdate()),103) + ' ' + convert(varchar,dateadd(m, 1, getdate()),114)

  • 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()))

  • 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())

  • 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:

    PRINT

    '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

  • 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