Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8796937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:44:18+00:00 2026-06-13T23:44:18+00:00

What is the best way to generate a regexp time range ( YYYYMMDD )

  • 0

What is the best way to generate a regexp time range (YYYYMMDD) from two dates from a different format, let’s say (D.M.YYYY)? For example, three separate cases:

input date 1 = "20.11.2012"  
input date 2 = "27.11.2012"  
Wanted result = "2012112[0-7]"

input date a = "31.12.2011"  
input date b = "6.1.2012"  
Wanted result = "20111231\\|2012010[1-6]"  

input date x = "28.1.2012"  
input date y = "4.2.2012"  
Wanted result = "2012012[8-9]\\|2012013[0-1]\\|2012020[1-4]"

Or is there a better regexp for getting the same result than what the “Wanted result” achieves in the current form? A week will suffice in the total range, and longer than 30 days is not required.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:44:19+00:00Added an answer on June 13, 2026 at 11:44 pm

    Given that your range is small (7 days), it’s a lot easier to simply generate all of the dates.

    Here is a script to do that:

    #!/bin/bash
    fromDate="$1"
    toDate="$2"
    
    # break the dates into array so that we can easily access the day, month and year
    IFS='.' read -a fromDateParts <<< "$fromDate"
    IFS='.' read -a toDateParts   <<< "$toDate"
    
    # loop until the days, months and years match on both dates
    while [[ "${toDateParts[0]}" -ne "${fromDateParts[0]}" || "${toDateParts[1]}" -ne "${fromDateParts[1]}" || "${toDateParts[2]}" -ne "${fromDateParts[2]}" ]]
    do
        # add the date to the pattern
        printf -v date "%d%02d%02d" "${fromDateParts[2]}" "${fromDateParts[1]}" "${fromDateParts[0]}"
        pattern="$pattern|$date"
    
        ((fromDateParts[0]++))
    
        # reset days and increment month if days exceed 31
        if [[ "${fromDateParts[0]}" -gt 31 ]]
        then
            fromDateParts[0]=1
            ((fromDateParts[1]++))
    
            # reset month and increment year if months exceed 12
            if [[ "${fromDateParts[1]}" -gt 12 ]]
            then
                fromDateParts[1]=1
                ((fromDateParts[2]++))
            fi
        fi
    done
    
    # finally add the toDate to the pattern
    printf -v date "%d%02d%02d" "${toDateParts[2]}" "${toDateParts[1]}" "${toDateParts[0]}"
    pattern="$pattern|$date"
    
    # print the pattern, removing the first pipe
    echo "${pattern#?}"
    

    Example Usage:

    $ dateRange.sh 28.1.2012 4.2.2012
    20120128|20120129|20120130|20120131|20120201|20120202|20120203|20120204
    
    $ dateRange.sh 31.12.2011 6.1.2012
    20111231|20120101|20120102|20120103|20120104|20120105|20120106
    
    $ dateRange.sh 28.1.2012 4.2.2012
    20120128|20120129|20120130|20120131|20120201|20120202|20120203|20120204
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the easiest/best way to generate Java from an XSD using MOXy under Maven-3?
What is the best way to generate C# classes from multiple XSD schema files?
What is the best way to generate barcodes from strings in a rails app?
What's the best way to generate 5 random non duplicating integers from 0 -
what is the best way to generate a csrf token and verify. From what
What is the best way to generate a current datestamp in Java? YYYY-MM-DD:hh-mm-ss
What is the best way to generate image data from the contents of an
What is the best way to generate a dotplot with two factors like this,
What is the best way to generate PDF reports from GAE Java? No SAAS
What is the best way to generate a unique hardware ID on Microsoft Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.