Results 1 to 3 of 3

Thread: Output user input as a date

  1. #1
    Join Date
    Oct 2010
    Location
    Sweden
    Beans
    822
    Distro
    Ubuntu 16.04 Xenial Xerus

    Output user input as a date

    Hi I'm back with more questions.

    How can I take user input and display that as a date?

    For example, I can use:
    Code:
    read -p "Enter the DATE: " When
    This will give $When the value of whatever the user types, right?

    My question is if the user types in the word Today, how can I have the script assign Today the meaning of the current date and place today's date in the $When variable.

    In the end this script writes the variables $When $Name and $Duration to a text file that logs hours spent on different jobs.
    Thank you,
    GG -----------
    GUI we don't need no stinking GUI: A collection of Bash scripts
    Mutt (email), cmus (music),Google Calendar and Google Tasks cli

  2. #2
    Join Date
    Apr 2012
    Beans
    7,004

    Re: Output user input as a date

    You could maybe use the system 'date' function

    Code:
    $ date --date="Today"
    Tue Apr 23 10:47:11 EDT 2013
    Code:
    $ when="Today"; when=$(date --date="$when"); echo "$when"
    Tue Apr 23 10:48:36 EDT 2013
    It's pretty good at understanding what you mean but you will nevertheless need to add some way to handle invalid input

    Code:
    $ date --date="Next Thursday"
    Thu Apr 25 00:00:00 EDT 2013
    
    $ date --date="groundhog day"
    date: invalid date `groundhog day'

  3. #3
    Join Date
    Oct 2010
    Location
    Sweden
    Beans
    822
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Output user input as a date

    Hey thanks man - I'll give that a try!
    Thank you,
    GG -----------
    GUI we don't need no stinking GUI: A collection of Bash scripts
    Mutt (email), cmus (music),Google Calendar and Google Tasks cli

Tags for this Thread

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
  •