Results 1 to 5 of 5
  1. #1
    G00seEggs is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    3

    Rounding to Day of Week and Adding value; i have both parts can't combine correctly

    Final goal is getting both parts below combined together. Round then perform the adding function. I have tried multiple options but I cannot figure them out. I have them broken down into both sections that work but I am not sure how to combine the logic.

    Product_Table only contains two columns; both currently set as text
    LIFE
    INTERVAL



    Thanks
    1st part:
    Take today's date, move to the next Monday: If day of week = Monday move to next Monday
    *this line seems to accomplish this correctly*
    DateAdd("d",8-Weekday(Date(),2),Date())



    2nd part:
    If INTERVAL equals = "days" add value of LIFE to date in total number of days;display mmddyy format


    If INTERVAL equals = "months" add value of LIFE to date in total number of Months;display mmddyy format
    *this line seems to accomplish this correctly*
    SELECT Switch(
    Product_Table.Interval="days",Format(DateAdd("d",P roduct_Table.[Life],Dat()),"mmddyy"),
    Product_Table.Interval="months",UCase(Format(DateA dd("m",Product_Table.[Life],Date()),"mmddyy")),
    1=1,"NO FORMAT")
    AS XP_DATE, *
    FROM Product_Table;


    I cannot figure out how to combine the two procedures, thanks to any assistance or guidance provided. It won't let me upload my sample database.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    Format(DateAdd(IIf([Interval]="days","d","m"),Product_Table.[Life],Date()),"mmddyy")

    or

    Format(DateAdd(Left([Interval],1),Product_Table.[Life],Date()),"mmddyy")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    G00seEggs is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    3
    Quote Originally Posted by June7 View Post
    Format(DateAdd(IIf([Interval]="days","d","m"),Product_Table.[Life],Date()),"mmddyy")
    or
    Format(DateAdd(Left([Interval],1),Product_Table.[Life],Date()),"mmddyy")
    I agree these work better and are clearer, but I still don't understand how to includes the weekly rounding option.

    Where do I put this logic DateAdd("d",8-Weekday(Date(),2),Date())<-- related to the previous calculations which finds the next Monday for day of week. I am new to SQL and it's taken me almost 3 hours to even get the rounding and other logic working. I simply can't figure out how to combine the two together.


    sample: if INTERVALS = days and LIFE = 14

    Today is 01/19/16 the logic should be advance to next Monday -> 01/25/16
    Then perform IIF statement: INTERVAL = days. add 14 days to previously found Monday: 01/25/16 + 10 days.
    Final Output for the column is: 02/08/16

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,956
    If I understand, you want to first calculate the upcoming Monday. Today is Tuesday 1/19/2016 so you want 1/25/2016? Then add either days or months of LIFE to that value? Maybe:

    SELECT *, DateAdd("d",8-Weekday(Date(),2),Date()) AS NextMon, Format(DateAdd(Left([Interval],1),Product_Table.[Life],[NextMon]),"mmddyy") AS XP_Date FROM Product_Table;


    Why can't you upload db? Follow instructions at bottom of my post.


    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    G00seEggs is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2016
    Posts
    3
    Thank you so much, I was missing the first section of that process. That is exactly what I was looking for.

    The upload process kept saying failed, tried IE, Fox and Chrome.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 06-19-2015, 03:37 PM
  2. Replies: 4
    Last Post: 06-22-2014, 06:47 PM
  3. Replies: 15
    Last Post: 12-10-2012, 06:37 PM
  4. Adding the day of the week to a date field
    By cschieff in forum Reports
    Replies: 2
    Last Post: 10-24-2012, 02:47 PM
  5. Replies: 3
    Last Post: 08-02-2012, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums