+ Reply to Thread
Results 1 to 4 of 4

Return value based on Date/Time format

  1. #1
    Forum Contributor
    Join Date
    06-27-2013
    Location
    Nebraska
    MS-Off Ver
    Office 365
    Posts
    115

    Return value based on Date/Time format

    Hello,

    I am trying to write a formula that will read the load time in column A and return if that event occurred on 1st or 2nd shift. Anything that occurs before 3PM, or 15:00:00, should return a 1 for 1st shift where anything occurring afterwards would return a 2 for 2nd shift. The data in column A comes from another database and is formatted as "5/2/2023 5:42:47 PM".

    shifts.PNG
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,033

    Re: Return value based on Date/Time format

    change B2 to include the date associated with the data as you have in column A. Then the following will work =IF(A6<$B$2,1,2). If you have a date in Column A, then you need to have the same date in B2
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,926

    Re: Return value based on Date/Time format

    Another possibility is to strip the date information from the data in column A before making the comparison (usually a MOD() function). =IF(MOD(A6,1)<$B$2,1,2)

    Observation. You claim that every time before 15:00 should be considered shift 1, but your sample file from row 20 to row 34 (times from 13:00 to 15:00) you have indicated a desired result of 2. A typo on your part, or am I misunderstanding the desired logic? Or maybe 13:00 divides shift 1 and shift 2 and not 15:00?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Contributor
    Join Date
    06-27-2013
    Location
    Nebraska
    MS-Off Ver
    Office 365
    Posts
    115

    Re: Return value based on Date/Time format

    Quote Originally Posted by MrShorty View Post
    A typo on your part, or am I misunderstanding the desired logic? Or maybe 13:00 divides shift 1 and shift 2 and not 15:00?
    That was a typo on my part.

    Alan, that does work as long as the dates are the same. I am working with data across multiple dates so I needed to look only at the time portion. I ended up using the following formula =IF(A6-INT(A6)<$B$2,1,2) to remove the date portion from Column A.
    Attached Files Attached Files
    Last edited by erice; 05-05-2023 at 01:48 PM.

+ 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. [SOLVED] Conditional format or data validation for an entered date&time based on another cell
    By grasshopper82 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-21-2021, 09:56 PM
  2. [SOLVED] Converting Unusable Time / Date Format To Usable Time / Date Format
    By Gtrtim112 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-05-2019, 11:25 AM
  3. [SOLVED] Converting Date & Time (General format) to Date (Date format)
    By supremenuts in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2017, 12:55 PM
  4. [SOLVED] check a date and return different values based on time and day of week
    By garyfahy in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-22-2014, 07:26 AM
  5. Return value based on closest time/date and name
    By Steven87 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-11-2013, 03:52 PM
  6. [SOLVED] How do I convert imported date/time data to date/time format?
    By andykent99 in forum Excel General
    Replies: 4
    Last Post: 01-03-2013, 07:47 AM
  7. [SOLVED] Return indicated value based on time elapsed since specified date
    By edeneyes in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-15-2012, 10:53 AM

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