Sponsored Content
Top Forums Shell Programming and Scripting Echo date variable from data input to a script Post 302478235 by ctsgnb on Tuesday 7th of December 2010 11:56:18 AM
Old 12-07-2010
Have a look at the following thread especially at the code provided in post #9 :

By "use cal", i was thinking : use it to validate that the entered date is OK (also handle leap year)

Code:
echo "Enter the year on 4 digit) :"
read y
echo "Enter the month on 2 digit) :"
read m
echo "Enter the day on 2 digit) :"
read d

chk_date(){
typeset -i y m d
y="${1%????}" ; t="${1%??}" ; m="${t#$y}" ; d="${1#??????}"
cal $m $y 2>/dev/null | tail +3 | sed -e 'N;N;N;N;N;s/\n/ /g' | grep " $d" >/dev/null 2>&1 && return 0 || return 1
}

chk_date "$y$m$d" && echo "Date Valide" || echo "Date not Valide"

Of course this short code does not behave exactly the way you want, but it gives some clue... and it handles leap year Smilie

---------- Post updated at 05:56 PM ---------- Previous update was at 05:50 PM ----------

Of course if you have some recent date tools that can handle it better, you should of course use it instead of my hugly code Smilie
This User Gave Thanks to ctsgnb For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to find files on a given input date

Hello gurus, I need to write a script to find out all the file that got changed on a specific folder since a given input date (Date to be given as Input) Thanx (1 Reply)
Discussion started by: ar.karan
1 Replies

2. Shell Programming and Scripting

Help with Creation of Script to Input Separators in Data

Hi all, I have one problem that is preparing datas so I can run a script to extrat informations for my statistic reports. I receive some datas, that are informations mixed and I need to separate them to analyse. This is an exemple of datas:... (8 Replies)
Discussion started by: Alexis Duarte
8 Replies

3. Shell Programming and Scripting

problem piping input to script with echo

I am trying to have a script run without interaction from the command line. So in my script i have a line like this echo -e "\n\n\ny\ny\n" | ./script the goal being the ability to mimic 3 Enter presses and 2 'y/n' responses with 'y' followed by enter. For some reason tho, it is not... (1 Reply)
Discussion started by: mcdef
1 Replies

4. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

5. Shell Programming and Scripting

Script asks to input data

Hi, I have three different files about a warehouse's stock status. Each file shows storage locations, stored product names, quantity of the part and at last column, its price. When there is a change in price, I open those files one by one, search related product name at each row and change... (4 Replies)
Discussion started by: baris35
4 Replies

6. Shell Programming and Scripting

Input date on script

How can I allow users to change the date and time in a script? Say the user1 wil login and he will be inputting the desired date (example format below). I will need this script so the user can login and change the date anytime during the day. I will not allow him to use any command except the date... (2 Replies)
Discussion started by: lhareigh890
2 Replies

7. Shell Programming and Scripting

Script to get previous date for the given input date..

hi all, need a script or command to get the previous date for the given input date... like in my script i will pass date as input parameter like 2014-12-01 and i want the output as previous date.. ie.. 2014-11-30 (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

8. UNIX for Dummies Questions & Answers

UNIX shells script to echo out the date value

I appreciate if someone answer this question for my learning purpose: Given a filename structure of a COUNTRY CODE, file type, date (YYYYMMDD) and two digit attempt number with an extension of ".dat", write a UNIX shells script to echo out the date value. Example: ... (1 Reply)
Discussion started by: shumail
1 Replies

9. Shell Programming and Scripting

Variable input to awk script

Hi guys, I wrote the following function to compare two csv files column by column. However, sometimes the input needs to be sorted before parsing it to awk. I can do this by changing the awk arguments, but I would like to make this variable if possible. The below doesn't work since the... (3 Replies)
Discussion started by: Subbeh
3 Replies

10. Shell Programming and Scripting

Enhance existing script: Extract Multiple variables & Input in an echo string

Hi Experts I need your help to optimize my script to execute better as I have nearly 1M records & the script is taking close to 40 minutes to execute, so would need support on a faster alternative. Input: file {"house":"1024","zip":"2345","city":"asd","country":"zzv"}... (2 Replies)
Discussion started by: nk1984
2 Replies
HTML::FormHandler::Field::Date(3pm)			User Contributed Perl Documentation		       HTML::FormHandler::Field::Date(3pm)

NAME
HTML::FormHandler::Field::Date - a date field with formats VERSION
version 0.40013 SUMMARY
This field may be used with the jQuery Datepicker plugin. You can specify the format for the date using jQuery formatDate strings or DateTime strftime formats. (Default format is format => '%Y-%m-%d'.) d - "%e" - day of month (no leading zero) dd - "%d" - day of month (two digit) o - "%{day_of_year}" - day of the year (no leading zeros) oo - "%j" - day of the year (three digit) D - "%a" - day name short DD - "%A" - day name long m - "%{day_of_month" - month of year (no leading zero) mm - "%m" - month of year (two digit) "%m" M - "%b" - month name short MM - "%B" - month name long y - "%y" - year (two digit) yy - "%Y" - year (four digit) @ - "%s" - Unix timestamp (ms since 01/01/1970) For example: has_field 'start_date' => ( type => 'Date', format => "dd/mm/y" ); or has_field 'start_date' => ( type => 'Date', format => "%d/%m/%y" ); You can also set 'date_end' and 'date_start' attributes for validation of the date range. Use iso_8601 formats for these dates ("yyyy-mm- dd"); has_field 'start_date' => ( type => 'Date', date_start => "2009-12-25" ); Customize error messages 'date_early' and 'date_late': has_field 'start_date' => ( type => 'Date, messages => { date_early => 'Pick a later date', date_late => 'Pick an earlier date', } ); If form has 'is_html5' flag active it will render <input type="date" ... /> instead of type="text" AUTHOR
FormHandler Contributors - see HTML::FormHandler COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Gerda Shank. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-25 HTML::FormHandler::Field::Date(3pm)
All times are GMT -4. The time now is 04:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy