SPONSORS:






User Tag List

Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Aug 2001
    Location
    Ireland
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using the AddDateTime Function to add 7 days to the current date

    Hi All,

    Happy New Year !

    I am using the following code to do the above:
    [ ] DATETIME NewDate
    [ ] string sNewDate
    [ ] NewDate = GetDateTime ()
    [ ] sNewDate = FormatDateTime (DayAndTime, "dd/mm/yyyy")
    [ ] Print (sNewDate)
    [ ] Print (AddDateTime (sNewDate, 7))

    The script runs but I get the following error: *** Error: Incompatible types -- '07/01/2002' is not a valid date

    The first Print gives me this: 07/01/2002
    which is exactly correct. All I want to do
    is add 7 days to this to get 14/01/2002

    Any help would be appreciated.

    Cheers,
    Conor

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

  2. #2
    Member
    Join Date
    Aug 2001
    Location
    Ireland
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Using the AddDateTime Function to add 7 days to the current date

    One Correction:

    sNewDate = FormatDateTime (NewDate, "dd/mm/yyyy")


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

  3. #3
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Using the AddDateTime Function to add 7 days to the current date

    I can see two places where you will get an type-casting error in your code; you are passing a STRING variable into AddDateTime(), which won't work. You are also passing a DATETIME variable into Print(), which will work, though I find it preferable to only ever pass in STRING variables, just for safety's sake.
    Try the following repairs:
    - pass in NewDate to AddDateTime(), not sNewDate.
    - declare a new DATETIME variable to hold the return value from AddDateTime().
    - declare a new STRING variable, which you can use to get a string-equivalent of your new DATETIME, using FormatDateTime() again like you did the first time.
    - pass that string variable into Print(), like you did the first time you called Print().

    Also CPFineos is right, you haven't declared any variable called DateAndTime in your code snippet, and NewDate is the one which is appropriate there in the FormatDateTime() function call.


    [This message has been edited by vincebowdren (edited 01-08-2002).]

  4. #4
    Member
    Join Date
    Aug 2001
    Location
    Ireland
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Using the AddDateTime Function to add 7 days to the current date

    Thanks Vince

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

  5. #5
    Member
    Join Date
    Dec 2001
    Location
    chennai,TN,India
    Posts
    30
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Using the AddDateTime Function to add 7 days to the current date

    Check this one:
    [ ] DATETIME newdate =GetDateTime()
    [ ] newdate=AddDateTime(newdate,7)
    [ ] STRING s=FormatDateTimenewdate,"dd/mm/yyyy")
    [ ] print(s)


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

  6. #6
    Member
    Join Date
    Aug 2001
    Location
    Ireland
    Posts
    64
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Using the AddDateTime Function to add 7 days to the current date

    Thanks rasu - that worked great
    Also thanks to Vince - yours suggestion for correction worked as well

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

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 05:37 PM.

Copyright BetaSoft Inc.