Results 1 to 4 of 4
  1. #1
    Join Date
    May 2011
    Posts
    2

    Red face Unanswered: DateAdd Need Help Very Bad

    Hi All,

    Im new here and to programming, I have a project and I would like to know how I can make DateAdd function to get the interval value (number) from a table and save the result to a table.

    DATEADD(<date/time_part>, <number>, <date>)

    Sample : =DateAdd("m",4,[hdate])

    Please advise.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Do you mean storing the result of the DateAdd function applied to each row from a table into a column of another table, or retrieve the date from a single row, use it with DateAdd and store the result? If you prefer: is it for a single date value (one row) or for every row of a table (or a subset of these rows)?
    Have a nice day!

  3. #3
    Join Date
    May 2011
    Posts
    2
    retrieve the date from a single row use it with dateadd and store the result, it is for every row of the table

    i have 20 sample data with hiredate and want them to automatically show their tentative leave date after 4 months (future date) using dateadd and store the result in a table.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can use a query, which is faster than VBA.

    1. If the computed values must be stored in the same table as the original value:
    Code:
    UPDATE Tbl_Src_Dest 
    SET Tbl_Src_Dest.Field_Date_Dest = DateAdd("m", 4, Tbl_Src_Dest.Field_Date_Src);
    2. If the computed values must be stored in existing rows of another table:
    Code:
    UPDATE Tbl_Source INNER JOIN 
           Tbl_Destination ON 
           Tbl_Source.Field1=Tbl_Destination.Field1 
    SET Tbl_Destination.Field_Date = DateAdd("m", 4, Tbl_Source.Field_Date);
    3. If the computed values must be stored in new rows of the destination table:
    Code:
    INSERT INTO Tbl_Destination ( Field1, Field_Date )
    SELECT Tbl_Source.Field1, DateAdd("m", 4, Tbl_Source.Field_Date)
    FROM Tbl_Source;
    Also notice that storing computed values into tables it is not recommended: sooner or later this will create data incoherences.
    Have a nice day!

Posting Permissions

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