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 9061617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:31:53+00:00 2026-06-16T15:31:53+00:00

I need some help here. I stuck in my programming in manipulation of my

  • 0

I need some help here. I stuck in my programming in manipulation of my date.
Date is in format of DD-MON-YY and I want to check it if the user input the correct date format. So I create a function to test the date, the month and the year separately, but the function also read the “-” in the format so I decided to use this code:

echo -n " Date [ DD-MON-YY ]:"  #user will input the date
        read dates
        vardate=$ echo "$dates" | tr "-" " "
        echo $vardate

I use that so there will be no problem with “-” character when I call the function.
but the problem now is how can I save the 3 parts of the date [day, month, year]?? so my function can evaluate it properly.

My function:

datefxn(){

d1 = $date1
d2 = $month1
d3 = $year1

########## check the DAY #####################

test ${#d1} -eq 2 || s=" INVALID!"

if [ "$d1" -gt 0 ] && [ "$d1" -le 31 ]
then
    break ;;
else
    echo "Month is OUT OF RANGE!"
fi

########## check the DAY #####################  

test ${#d2} -eq 3 || s=" INVALID!"

MONTH=(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
echo "${MONTH[@]}"

for element in "${MONTH[@]}"
do
if [[ $element == $d2 ]]
then
       echo " a "
      break
        else
        echo " WAAA "
    fi
    done
########## check the YEAR ##################### 

test ${#d3} -eq 2 || s=" INVALID!"


} #end datefxn()
  • 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-16T15:31:54+00:00Added an answer on June 16, 2026 at 3:31 pm

    Something like this:

    #!/bin/bash
    datefxn () {
            d1=$1
            d2=$2
            d3=$3
            echo "Date is $d1"
            echo "Month is $d2"
    }
    
    inp='24-12-2004';
    vardate=$(echo "$inp" | tr "-" " ")
    datefxn $vardate
    

    The above solution is given to fix your code.

    Update:
    A better approach would be like this one using arrays and in-place substitution:

    #!/bin/bash
    
    datefxn () {
            dt=($(echo ${1//-/ }))
            echo "Date  is  ${dt[0]}"
            echo "Month is  ${dt[1]}"
            echo "Year  is  ${dt[2]}"
    }
    
    inp='24-12-2004';
    datefxn "$inp"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck here and need some serious help. I had to do some
Im stuck in my project here and i really need some help! I have
Ok, I'm stuck, need some help from here on... If I've got a main
i need some help here. I will like to transfer an Jpg or PNG
Well i need some help here i don't know how to solve this problem.
I need some advanced CSS help here. I have a login button and a
I need some help in understanding what is happening here .I am getting a
I need some help. Here's what I'm getting right now: img ref I need
I need some help extracting the following bits of information using regular expressions. Here
I'm in need of some basic TSQL help. Here's my table layout: Orders Table

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.