+ Reply to Thread
Results 1 to 31 of 31

Formula to calculate dates based off RIGHT CMD

  1. #1
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Formula to calculate dates based off RIGHT CMD

    So what I am looking to do in excel is build a calculations date table that works off numbers only, no slash marks, no dashes.

    =RIGHT(H188,2)-RIGHT(G188,2)

    The purpose of this calculation is to take the date 20171102 and minus it from 20171209 but here is where it gets tricky... I need the calculation to add one more day for every calculation... but if the day falls under a saturday or sunday, i need the data to deduct the date from the calculation... i also need the data to add only days, not by the hundreds but by the calendar dates only. If excel was to do =H188-G188, this would give me negative thirty seven ( -37 ) and I do not want the column to display any negatives period. I also want the ability to add an additional column as additional dates in case the person would want to later change the approved date which would change the days taking off work authorizing a new calculation. for example... IF I188 was 20140102 but H188 is 20131201 and G188 is 20131229 then the days taken would be an additional +3 to include 20140101 but since that is a holiday, the date shouldn't be counted.


    Is this possible in an excel spreadsheet? The code what i have above is sufficient but I need help completing it. Thank you.

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Formula to calculate dates based off RIGHT CMD

    Its easily manageable in Excel but Id recommend creating a quick example workbook showing a couple of examples and the answers you'd expect. If you could also break down the instructions a bit more it might make it easier as well as currently theres a lot going on and its hard to extract exactly whats needed.

    What I did get from it was the following:

    calculate how many days are between 09/12/2017 and 02/11/2017, thats fairly straight forward however I didnt understand the next bit "I need the calculation to add one more day for every calculation... but if the day falls under a saturday or sunday" what i dont understand is what day are we checking if Saturday or Sunday? the answer is currently 37 but are you wanting to check thats a weekend day (which obviously isnt possible to check) or one of the original dates?
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    I didnt understand the next bit "I need the calculation to add one more day for every calculation...
    so lets say im taking monday off, thats considered one day even if i return that same day... which excel counts that day as zero....i need excel to count that day as one
    and i do not want excel to count the dates as 11/2/2017 because I have a specific formatting for dates which is the year first, then the month and the day.


    but if the day falls under a saturday or sunday" what i dont understand is what day are we checking if Saturday or Sunday?
    the answer is currently 37 but are you wanting to check thats a weekend day (which obviously isnt possible to check) or one of the original dates?

    we're checking both but i had an idea... if we could create a database with all days of saturdays and sundays annotated... could we pull from that database and if the data is true, excel should not
    count that day and this would mean 36 (because you said 37, i removed a day which is what exactly i want the code to do); the database should be accessable in a seperate tab which i could access and change
    anytime.

    I have attached an example book as requested.
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Formula to calculate dates based off RIGHT CMD

    You seem to be making life very difficult: you could enter dates in standard format and display as "yyyymmdd" OR leave as you have but convert in Excel format In formulae) and use a function such as NETWORKDAYS.INTL which allows you to count working days and select your non_working days.

  5. #5
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    NETWORKDAYS.INTL definitely sounds like what i need.

    I just need the right code to execute the command correctly without an error.
    Last edited by randy2012; 02-17-2017 at 01:44 PM.

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Formula to calculate dates based off RIGHT CMD

    I just need the right code to execute the command correctly without an error.
    ... not sure what you mean by this.

    Nor did I really understand what your final outcome should be (sorry!)

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula to calculate dates based off RIGHT CMD

    If I understand correctly you don't want "helper" columns to convert to actual dates.

    Try this array entered formula. If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    It does not include weekends, but can be modified to exclude any days of the week you like ... up to 6 of them.


    G
    H
    I
    8
    20170330
    20170221
    28
    Dave

  8. #8
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    nice. Exactly. I think i made a mistake with the dates.

    20170330 20170421
    20170330 20170501
    20170330 20170630

    those dates are more accurate in terms of calculating...i have attached the sheet...the code u gave me is in there but there is a value error. thanks.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Formula to calculate dates based off RIGHT CMD

    You have an error as you had 3 formulas in one cell.

    This in L8

    =NETWORKDAYS.INTL(MIN(DATE(--LEFT(G8:H8,4),--MID(G8:H8,5,2),--RIGHT(G8:H8,2))),MAX(DATE(--LEFT(G8:H8,4),--MID(G8:H8,5,2),--RIGHT(G8:H8,2))),1)

    returns 17 as an answer. the others return 23 and 67

    Delete the formulae in L8:L10 and re-add the one above in L8:

    Enter with Ctrl+Shift+Enter

    Copy down.

  10. #10
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    Nice. This is the only issue im encountering when i enter the code otherwise its perfect and works exactly as what i want!

    I have followed your instructions and they work nicely. Excel isn't behaving when it comes to this spreadsheet attached which is where im putting the code into.

    sorry if im acting a little new, i am really trying to seriously get into this coding lol.
    Attached Files Attached Files
    Last edited by randy2012; 02-17-2017 at 04:44 PM.

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Formula to calculate dates based off RIGHT CMD

    As previous stated TWICE you must enter the formula with Ctrl+Shift+Enter

    Hold down Ctrl+Shift keys then hit Enter


    See the attached which has formulae in G2 and H2 to count "lates" without needing add the "helper" columns.

    =SUMPRODUCT(--(D2:D7>C2:C7))

    and

    =SUMPRODUCT(--(E2:E7-D2:D7>1/12))

    do NOT set the range to whole columns but use a sensible maximum e,g E2:E5000

    the CF is set to whole column as well
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    =NETWORKDAYS.INTL(MIN(DATE(--LEFT(G8:H8,4),--MID(G8:H8,5,2),--RIGHT(G8:H8,2))),MAX(DATE(--LEFT(G8:H8,4),--MID(G8:H8,5,2),--RIGHT(G8:H8,2))),1)

    When I follow the instructions to Ctrl+Shift+Enter, it will only work on an empty spreadsheet but will NOT work on an existing spreadsheet attached to this message.

    I have tried Going to the Data Tab --> Text to Columns then change from Delimited to Fixed Width and made sure the format was on General, not text and clicked finish. I got the error code on the existing worksheet but on a new worksheet, I wouldn't receive any errors and the code would work perfectly.

    I saw your above post for Sumproduct but I think NETWORKDAYS.INTL is more suited towards my goal.

    I have two issues though... all weekend dates are NOT being counted.... I need the formula to count all weekend dates EXCEPT if the END DATE falls on a WEEKEND.

    Secondly, I want to replace the #VALUE! on all text boxes with a blank space or a 0 so i tried *IFERROR(#VALUE!,0)

    I tried the IFERROR formula and the results for each date was 0, effectively voiding the formula (making the days not show but instead show as 0 instead of the exact days taken as absence)

    Thanks in advance! please see attached worksheet for my example.
    Attached Files Attached Files
    Last edited by randy2012; 02-17-2017 at 08:15 PM. Reason: discovered weekends in the middle of the month were not being counted in the formula

  13. #13
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    sorry if im posting twice... but if i need to create a new thread, please let me know.

  14. #14
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Formula to calculate dates based off RIGHT CMD

    Try attachment. All ares non-array formula
    Attached Files Attached Files
    Quang PT

  15. #15
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    Same results but a different code. I like it. I only wish that the code counted all weekend days except the last day of that weekend which the day ends on.

    For example... If I take paid leave monday through sunday but im only paid until saturday, then sunday shouldn't count towards my paid vacation days that i have left with the company.

    another example...if i was to take say monday of next week until sunday of next month... all those days in the middle would be PAID by the company but if my paid vacation falls on a saturday or a sunday then i will not be charged a vacation day on that day.
    Last edited by randy2012; 02-18-2017 at 01:17 PM. Reason: to better describe what i need

  16. #16
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Formula to calculate dates based off RIGHT CMD

    I think you need explain more clearly the "pay" logic which (to me) is not obvious from your workbook.

    If I take paid leave monday through sunday but im only paid until saturday, then sunday shouldn't count towards my paid vacation days that i have left with the company

  17. #17
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    Quote Originally Posted by JohnTopley View Post
    I think you need explain more clearly the "pay" logic which (to me) is not obvious from your workbook.
    So The workbook has two sections. The section to the left counts the days that the person took actual leave which counts ALL DAYS within the year (all 365 days). The Left section which contains the exact same data is for pay which means the days counted for pay.

  18. #18
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula to calculate dates based off RIGHT CMD

    Quote Originally Posted by randy2012 View Post
    Same results but a different code. I like it. I only wish that the code counted all weekend days except the last day of that weekend which the day ends on.

    For example... If I take paid leave monday through sunday but im only paid until saturday, then sunday shouldn't count towards my paid vacation days that i have left with the company.

    another example...if i was to take say monday of next week until sunday of next month... all those days in the middle would be PAID by the company but if my paid vacation falls on a saturday or a sunday then i will not be charged a vacation day on that day.
    Quote Originally Posted by randy2012 View Post
    So The workbook has two sections. The section to the left counts the days that the person took actual leave which counts ALL DAYS within the year (all 365 days). The Left section which contains the exact same data is for pay which means the days counted for pay.
    I think the only way I am going to understand what you want is if you re-upload your workbook with all 6 of the expected values filled in manually.

  19. #19
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    Quote Originally Posted by FlameRetired View Post
    I think the only way I am going to understand what you want is if you re-upload your workbook with all 6 of the expected values filled in manually.
    As requested, please see attached
    Attached Files Attached Files

  20. #20
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Formula to calculate dates based off RIGHT CMD

    It appears your calculation is not based on working days but simply number of days between the two dates which I would have thought was incorrect.

    If the normal working week is Monday to Friday then surely holidays deducted are only 5 days in any weekly period e.g. start date is 20/02/2017 (Monday) and end date is 26/02/2017 (Sunday) then holiday is 5 days which is what NETWORKDAYS.INTL will return with parameter for weekend being 1 (Saturday/Sunday).

    Hence the result of 15 in your posted file.

    If you want 7 days, then I will not accept the job!!!
    Last edited by JohnTopley; 02-20-2017 at 10:08 AM.

  21. #21
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Formula to calculate dates based off RIGHT CMD

    @ randy2012

    I remain clueless.

    Still subscribed.

    Will watch.

  22. #22
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    Quote Originally Posted by JohnTopley View Post
    It appears your calculation is not based on working days but simply number of days between the two dates which I would have thought was incorrect.

    If the normal working week is Monday to Friday then surely holidays deducted are only 5 days in any weekly period e.g. start date is 20/02/2017 (Monday) and end date is 26/02/2017 (Sunday) then holiday is 5 days which is what NETWORKDAYS.INTL will return with parameter for weekend being 1 (Saturday/Sunday).

    Hence the result of 15 in your posted file.

    If you want 7 days, then I will not accept the job!!!
    Your right. Per the above worksheet i previously uploaded, The calculation is based on the total number of days between the two dates.

    For the other column, the calculation is the same except the last working day that falls under a weekend (Saturday or Sunday) will not count so that would result in that day not being counted in the calculation.

    So Monday through Sunday, Only Sunday should not count and Saturday will count unless its monday all the way through monday again then all dates will count. Makes sense?

    7 days lmao... i don't know what you mean here!! :P


    Quote Originally Posted by FlameRetired View Post
    @ randy2012

    I remain clueless.

    Still subscribed.

    Will watch.
    I'm basically looking for a excel to automatically calculate work days. For the right and left columns in the worksheet, i would like it to calculate, up to 120 days, the amount that the worker takes paid vacation leave. The left side will be the amount of work leave the worker would be charged. In this case, maybe NETWORKDAYS.INTL might not be suitable... I don't know if there is any other function available or a way to modify NETWORKDAYS.INTL to count all the days in the middle of the calculation so that those days are counted and the worker is paid.

  23. #23
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    sorry for posting twice. let me know if i need to make a new thread with a new question. thanks.

  24. #24
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    sorry for posting again. let me know if i need to make a new thread with a new question. thanks.

  25. #25
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Formula to calculate dates based off RIGHT CMD

    I have added Sheet1 with some calculations but need rationale explaining as to my mind it is inconsistent when I try and work out the logic for "Days Counted".
    Attached Files Attached Files

  26. #26
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    Quote Originally Posted by JohnTopley View Post
    I have added Sheet1 with some calculations but need rationale explaining as to my mind it is inconsistent when I try and work out the logic for "Days Counted".
    The company has a policy where any day that the employee has taken off but is not suppose to work will be paid but will not count towards the employee's vacation days.

    This is a company incentive that is highly popular with everyone. Just to clarify.

    <=== why NO Day deducted because column H date was Saturday ?
    <=== Day deducted because column I date was Saturday ?
    <=== Day deducted because column H date was Sunday ?

    Hopefully that explanation answered the above questions. The only thing is any slash marks that are used in the worksheet will not work for back office. thats why i have adopted YYYYMMDD
    Last edited by randy2012; 02-22-2017 at 12:51 AM.

  27. #27
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    I guess I cannot be helped. I will try to breakdown my explanation next time i post. Sorry for being vague and confusing.

  28. #28
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Formula to calculate dates based off RIGHT CMD

    The company has a policy where any day that the employee has taken off but is not suppose to work will be paid but will not count towards the employee's vacation days.
    Sorry to be dim but I don't know how we determine the above from your data. And there was still no clear explanation, based on the data, regarding my previous posting on re Saturday/Sunday.

    Take the first 2 examples:

    Both have start dates of Monday, finish of Saturday: the second has a week's extension with finish on Saturday BUT has a day deducted from "Days Counted. ????

    The third has Mon=>Sun AND has Day deducted from "Days Counted"

    What are the dates in J & K?


    NOTE: the dates in the example were formatted wirh "/" for my benefit
    Last edited by JohnTopley; 02-23-2017 at 03:52 AM.

  29. #29
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    Quote Originally Posted by JohnTopley View Post
    Both have start dates of Monday, finish of Saturday: the second has a week's extension with finish on Saturday BUT has a day deducted from "Days Counted. ????

    The third has Mon=>Sun AND has Day deducted from "Days Counted"

    What are the dates in J & K?


    NOTE: the dates in the example were formatted wirh "/" for my benefit
    Correct. The second finishes on saturday because saturday is a weekend date and the company will not charge that employee that day because its a non-working day. Non-working days are not counted in the spreadsheet so that calculations aren't changed.

    BUT if the employee decides to not call the company to let them know that he is returning on a non working day, that day he did not report in will be counted as a vacation day and he will have Sunday to report in or Sunday will be charged as well. Monday through Friday, regardless of employee status, will be charged by the back office, no exceptions. The only exceptions are weekends which are Saturday through Sunday which if he signed in on Sunday he will be charged as Monday Through Saturday.

    J and K columns dates are days that the employee will be charged, no exceptions. Those dates will be sent to the back office for processing.

    Note: If Column I has a date that is bigger then column H, Column I should be calculated instead of H because the employee is requesting more days off than his originally approved request which may be due to an emergency situation.

  30. #30
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,215

    Re: Formula to calculate dates based off RIGHT CMD

    BUT if the employee decides to not call the company to let them know that he is returning on a non working day, that day he did not report in will be counted as a vacation day and he will have Sunday to report in or Sunday will be charged as well. Monday through Friday, regardless of employee status, will be charged by the back office, no exceptions. The only exceptions are weekends which are Saturday through Sunday which if he signed in on Sunday he will be charged as Monday Through Saturday.
    BUT we have no way of knowing any of this from the information in the spreadsheet.

    So like "FlameRetired" I remain clueless: I have no more suggestions than those already offered.

  31. #31
    Registered User
    Join Date
    02-17-2017
    Location
    New York
    MS-Off Ver
    Excel 2013
    Posts
    30

    Re: Formula to calculate dates based off RIGHT CMD

    Quote Originally Posted by JohnTopley View Post
    BUT we have no way of knowing any of this from the information in the spreadsheet.

    So like "FlameRetired" I remain clueless: I have no more suggestions than those already offered.
    Okay then just ignore the dates for J and K...

    Im looking for just the calculation for the first column... I'll add a minus 1 or 2 for weekend dates on my own...


    Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Formula or VBA to calculate Interest based on different dates
    By zaska in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-29-2016, 12:53 PM
  2. Formula needed to calculate budget phasings based on dates
    By Kez35 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-23-2016, 05:22 AM
  3. Replies: 15
    Last Post: 12-08-2014, 10:21 PM
  4. [SOLVED] Formula to calculate sum/average based on number of unique dates in range
    By JennOlsen in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-19-2014, 06:47 PM
  5. Replies: 4
    Last Post: 10-15-2012, 07:38 AM
  6. formula to calculate a column based on dates in a different colum.
    By Pam in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-07-2005, 03:06 PM
  7. Formula to calculate a total in one range based on dates from another column
    By CarolineD in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-01-2005, 04:56 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1