How to compare current time with the input to variant?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to compare current time with the input to variant?
# 1  
Old 05-16-2011
How to compare current time with the input to variant?

Hi all,
I have a simple script follow:
-------------
#!/bin/bash
echo -n " Enter the date of today: "
read dateoftoday
-------------

Now I want to compare the variant $dateoftoday with date of the system (now) in order to prevent user inputs the past date to $dateoftoday. I want to make sure that $dateoftoday >= current date.

Pls help me to complete the script above with that above idea.

Thank you so much.
AXNB.
# 2  
Old 05-16-2011
Nuances matter: what level of time detail are you looking to compare? Is it just date? Not hours, minutes, seconds...?

Up front, I'd recommend you assign a value for your comparison BEFORE you'd echo the question to screen, and then format your comparison accordingly.
# 3  
Old 05-16-2011
Enter the date of the day in YYYYMMDD format, comparision will then be easier :
Code:
$(date +'%Y%m%d')

By the way, having a look at the script in post #9 of this thread https://www.unix.com/shell-programmin...zz-help-2.html may give you some clue
# 4  
Old 05-18-2011
my format is : DD-MM-YYYY
I have read the topic you gave, but have no clue.
Pls help me on this Smilie

Many thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If no input then set directory to current

Hi GUys I have a script where i am counting the number of files that the user has read permissions to in a folder . They are asked for this folder at the start if they dont enter anything then i want to be able to do the search on the current directory, can you help me with that part please... (25 Replies)
Discussion started by: johnnybananas
25 Replies

2. Shell Programming and Scripting

Compare between current and next line and print

Dear All I want below to compare two Consecutive line(i.e. current and next line). Based in that i need OP. Below is the IP file in that in i find "M" and if in next line i find "*" then i need both line in single line. If i dont find "*" in next line then i need to put commend "DOWN" . I am... (4 Replies)
Discussion started by: jaydeep_sadaria
4 Replies

3. Shell Programming and Scripting

Convert UTC time into current UNIX sever time zone

Hi guys thanks for the help for my previous posts.Now i have a requirement that i download a XMl file which has UTC time stamp.I need to convert UTC time into Unix server timezone. For ex if the time zone of unix server is CDT then i need to convert into CDT.whatever may be the system time... (5 Replies)
Discussion started by: mohanalakshmi
5 Replies

4. Shell Programming and Scripting

To get the time exactly 24hrs from the current time

Hi guys, I am having file which contains below data. 2012-04-24 08:40:13 10739022730 1027699274PersonInfoShipTO details missing FirstName,LastName, 2012-04-24 08:40:13 10739022730 1027699274PersonInfoShipTO details missing FirstName,LastName, 2012-04-24 08:40:13 ... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

5. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

6. Shell Programming and Scripting

AWK Compare previous value with current.

Hi, I have one small doubt how to go ahead and process the below requirement. File Content 1,abc,10 2,xyz,11 3,pqr,12 4,pqr,13 5,pqr,14 Output file expected: 1,mnq,1 1,ddd,2 1,qqq,3 1,sss,4 1,ddd,5 1,eee,6 1,fff,7 1,ddr,8 1,rrd,9 (3 Replies)
Discussion started by: dikesm
3 Replies

7. Shell Programming and Scripting

Compare current time to timestamp on a file

I'm trying to compare 2 dates between current time and the timestamp on a file. The date format is mmdd Both return Apr 1 but when using if statement line 11: Apr 1: command not found error is returned #!/bin/sh log="DateLog" Current_Date=`date +%b%e` Filepmdate=`ls -l /file.txt |... (1 Reply)
Discussion started by: cillmor
1 Replies

8. Shell Programming and Scripting

How to compare the mtime of a file with the current time?

Hi, I wondered if we could do this with shell script? How to compare the mtime of a file with the current time and check whether its less than 24 hours. Thanks.:b: (2 Replies)
Discussion started by: Krsh
2 Replies

9. UNIX for Dummies Questions & Answers

Need to get 4 Hrs back time and compare with successive time

Hi all, I am working on a script in which i need to get 4 hrs back time from the current time which i got from this perl function : `perl -e 'print localtime(time() - 14400) . "\n"'` now i need to get this in a loop and increment that time by 15 minutes i.e i=900(=15minutes) `perl... (2 Replies)
Discussion started by: maanik85
2 Replies

10. Shell Programming and Scripting

to compare latest logfile with the current running time of the script

how can i compare the latest log file with the current time.. consider i am running a script "a.sh" at 09:00 ( function of the script a.sh is to update the database ) this script is going to create logfile if the script is sucess in case of failure it is not going to create logfile.. ... (0 Replies)
Discussion started by: mail2sant
0 Replies
Login or Register to Ask a Question