+ Reply to Thread
Results 1 to 10 of 10

How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-01-06

  1. #1
    Registered User
    Join Date
    01-09-2021
    Location
    California
    MS-Off Ver
    Google Sheets
    Posts
    4

    How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-01-06

    Google Sheets: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-01-06 07:59)
    This is for Google Sheets, but I expect that there is something equivalent in Excel, so any help answering this would be appreciated!

    I'm trying to filter data to include rows that only have timestamps within certain date & time ranges. For example, I want to see a 24hr time window from 8am to 7:59am the next day; and another time window for a week from 8am Monday to 7:59am the next Monday.

    So far I have a working formula that lets me match for within the same date:
    =Filter(IMPORTcsv!A2:H, regexmatch(IMPORTcsv!F2:F, "t 2020-12-14"))

    How do I adapt this for more granular time range filtering?

    Thanks,
    RDDT

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-0

    There are no regex functions built into Excel. It is available only through VBA coding, which won't help with your Google problem. I'm moving your thread.

  3. #3
    Registered User
    Join Date
    01-09-2021
    Location
    California
    MS-Off Ver
    Google Sheets
    Posts
    4

    Re: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-0

    OK - Where did you move it to?

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-0

    You have found it - you are there now. The thread has been moved to the appropriate section for Google Sheet queries.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

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

    Re: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-0

    I've never used regular expressions, but my impression is that they are mostly a text manipulation tool. Spreadsheets (including Excel and Google Sheets) usually store dates/times as numbers and not text, so I usually expect a numeric manipulation rather than a text manipulation (the exception is manipulating a date stored as text into a number). The big questions I see up front are: 1) Are you date/time stamps stored as text or numbers and 2) Do you want to process these as text or numbers. A lot of the time, it makes more sense to process date/time data as numbers rather than text.

    For example, if I needed to "map" an 8 AM to 8 AM calendar day onto a standard midnight to midnight calendar day, I might simply subtract 1/3 (8 hours = 1/3 of a day) from the date/time stamps in a helper column to get a column that maps my date/time stamps onto a standard midnight to midnight calendar date. If I need to filter by two date/time stamps (say to show results between day1 at 8 AM and day2 at 8 AM), I can simply filter for dates greater than ore equal to the first time stamp and less than the second time stamp. (I think that would be something like =FILTER ( data range,date column >= timestamp1,date column < timestamp2 ).

    Not sure any of that helps, but I'd start with the question of text or number and go from there.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-0

    Quote Originally Posted by rddt View Post
    OK - Where did you move it to?
    When a post is moved, any links to the post continue to resolve to the same post, so you don't have to do anything different. The effect is that anyone looking at the Excel Functions forum won't see it in the list, but anyone looking at the Other Platforms list will.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-0

    Quote Originally Posted by MrShorty View Post
    [...]it makes more sense to process date/time data as numbers rather than text.
    I completely agree with this and didn't look at what you were actually trying to do at first. I don't know if Google sheets allows INT to be used in an expression like this, but this is the general thinking to pursue (I think Excel would require this to be an array formula in some versions):


    Formula: copy to clipboard
    Please Login or Register  to view this content.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-0

    Quote Originally Posted by MrShorty View Post
    I've never used regular expressions, but my impression is that they are mostly a text manipulation tool.
    FTR regexp is 100% a text tool. It is a pattern-matching language. It can test a string to see if a matching pattern is found, and also make replacements to text based on those patterns. Its origin goes back to the 1950s, but I'm not sure how long it has had a VBA implementation.

    It is very powerful though can be written in a very dense, complex way. For example, this is a pattern to test for a well-formed email address based on the RFC 5322 standard:

    ^([A-Za-z0-9!#$%&'*+\-/=?\^_`{|}~]([.A-Za-z0-9!#$%&'*+\-/=?\^_`{|}~]*[A-Za-z0-9!#$%&'*+\-/=?\^_`{|}~]){0,1})@(([A-Za-z0-9]([-A-Za-z0-9]*[A-Za-z0-9]){0,1}\.)+(xn--[-A-Za-z0-9]*|[A-Za-z]{2,}))$

  9. #9
    Registered User
    Join Date
    01-09-2021
    Location
    California
    MS-Off Ver
    Google Sheets
    Posts
    4

    Re: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-0

    Thanks MrShorty for your idea of converting to a number with a helper column. The date (in military time) is currently formatted as text like so: "t 2021-01-05 08:00" and ""t 2021-01-05 22:59"
    Is there an easy way to convert this to a number and do the comparisons you suggest? Perhaps the number manipulations can be combined with the regex text manipulations for the best of both worlds.

    FYI the goal is to filter by both 8am-7:59am daily format as well as a full week format 8am Mon -7:59am next Mon.

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

    Re: How to use Regexmatch to filter ranges of Times & Dates (ie, 2021-01-05 08:00 - 2021-0

    Your tab names imply that these are coming from text (.csv) files. I'm not familiar with how Google sheets imports text files, but it could be useful to review and research the importation process and see if you can convince the importation to import as date/time serial number. Google sheets has a DATEVALUE() function like Excel, if you decide to convert from text to number after import, but I'm not sure exactly how it behaves relative to different DMY, MDY, etc variations. Someone more familiar with text to number conversions in Google Sheets will need to comment (or someone will need to take a few minutes of trial and error to figure it out).
    FYI the goal is to filter by both 8am-7:59am daily format as well as a full week format 8am Mon -7:59am next Mon.
    I'm not sure exactly what it means to you to filter by day and week, but, as I noted before, once the date/times are entered as numbers, then you should be able to use some kind of "date / time >= date /time [ and ] date / time < datetime " criteria to filter for a given date or week.

+ 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. Call in the Cavalry - 2021
    By AliGW in forum The Water Cooler
    Replies: 59
    Last Post: 01-07-2022, 12:58 PM
  2. Hilfe - Chef will Umsatzprognose 2021 von Subunternehmer
    By Des Nicolchen in forum Non English Excel
    Replies: 0
    Last Post: 01-09-2021, 09:32 AM
  3. Hilfe - Chef will Umsatzprognose 2021 von Subunternehmer
    By Des Nicolchen in forum Excel General
    Replies: 0
    Last Post: 01-09-2021, 09:32 AM
  4. Hello 2021
    By clixkers in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 01-09-2021, 03:25 AM
  5. [SOLVED] Request for a macro insert name of the day in adjacent column to date in edairy 2021
    By buvanamali in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-25-2020, 07:38 PM
  6. [SOLVED] Formulating 1/1/2021-1/2/2021, 1/3/2021-1/9/2021 etc through one row.
    By jbposey86 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-24-2020, 08:27 PM
  7. Formula for Wednesdays & Sundays in 2021
    By Stev3 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-08-2020, 09:12 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