Max of Date DD-MM-YYYY 17:30


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Max of Date DD-MM-YYYY 17:30
# 1  
Old 03-13-2012
Max of Date DD-MM-YYYY 17:30

Hi,

I have two sets of dates as below. Need to find the maximum of them.

14-Feb-2006 17:30,02-Feb-2006 14:46
14-Feb-2006 17:30,02-Feb-2006 14:46
14-Feb-2006 17:30,02-Feb-2006 14:46
23-May-2006 18:25,02-Feb-2006 14:46
13-Feb-2006 12:00,02-Feb-2006 14:46
23-May-2006 18:25,02-Feb-2006 14:46
13-Feb-2006 12:00,02-Feb-2006 14:46
13-Feb-2006 12:00,02-Feb-2006 14:46
05-Oct-2007 09:19,02-Feb-2006 14:46
13-Feb-2006 12:00,02-Feb-2006 14:46
05-Oct-2007 09:19,02-Feb-2006 14:46
13-Feb-2006 12:00,02-Feb-2006 14:46
13-Feb-2006 12:00,02-Feb-2006 14:46

The differnce may be even in minutes

Please Suggest
# 2  
Old 03-13-2012
With GNU date:

Code:
#! /bin/bash
x=0
while IFS=',' read t1 t2
do
    if [ $x -lt $((($(date -d "$t1" +%s) - $(date -d "$t2" +%s)) / 60)) ]
    then
        x=$((($(date -d "$t1" +%s) - $(date -d "$t2" +%s)) / 60))
        y="${t1},${t2}"
    fi
done < inputfile
echo "$y"
echo "$x"

# 3  
Old 03-13-2012
Using ksh93
Code:
#!/bin/ksh93

maxdiff=0
while IFS=',' read date1 date2
do
   diff=$(( $(printf "%(%s)T" "$date1") - $(printf "%(%s)T" "$date2") ))
   (( diff > maxdiff )) && maxdiff=$diff
done < infile

mins=$((maxdiff % (60 * 60) / 60))
hours=$((maxdiff / (60 * 60)))

printf "%02d:%02d\n" $hours $mins

# 4  
Old 03-15-2012
Hi
Thanks for you Reply balajesuri and fpmurphy.

But Both are not working .
I am getting error. I am usinh ksh in solaris.

for balajesuri version
Quote:
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
./maxdate.sh: line 6: ( - ) / 60: syntax error: operand expected (error token is ") / 60")
For fpmurphy Version,
Quote:
./maxdate.sh[7]: ()T - ()T : syntax error
# 5  
Old 03-15-2012
Please explain what you mean by 'maximum of them' -- the maximum absolute date, or the widest range?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date format YYYY/MM/DD to DD/MM/YYYY

I am getting output of YYYY-MM-DD and want to change this to DD/MM/YYYY. When am running the query in 'Todd' to_date(column_name,'DD/MM/YYYY') am getting the required o/p of DD/MM/YYYY, But when am executing the same query(Netezza) in linux server(bash) am getting the output of YYYY-MM-DD file... (3 Replies)
Discussion started by: Roozo
3 Replies

2. Shell Programming and Scripting

Date Format MM/DD/YYYY

I am changing epoch times to dates. I was able to do the following: echo "$varx" | gawk '{print strftime("%c", $0)}' Mon Dec 31 16:26:40 2012 This changes the epoch date (which is what varx is) into localtime. However, my problem is that I only want 12/31/2012 and not the Mon Dec 31... (2 Replies)
Discussion started by: newbie2010
2 Replies

3. UNIX for Dummies Questions & Answers

Epoch date to YYYY/MM/DD or MM/DD/YYYY

I've seen a lot of posts on this and have tried the following: echo 1257000000| perl -e '($d,$m,$y)=(localtime(time-86400));$m+=1;$y+=1900;printf "$y/$m/$d\n";' But I am unable to convert a past Epoch date into a format such as YYYY/MM/DD or MM/DD/YYYY. I am using bash and don't know... (4 Replies)
Discussion started by: newbie2010
4 Replies

4. Shell Programming and Scripting

Date conversion help from dd/mm/yyyy to dd/Mon/yyyy i.e. 28/10/2012 to 28/Oct/2012

Hi I have a problem with Date format in my code. 1st I am trying to convert today's date to yesterday's using YESTERDAY3=`perl -e '@y=localtime(time()-86400); printf "%04d/%02d/%02d",$y+1900,$y+1,$y;$y;'` And once it is done I am trying to using the yesterday date in a grep command to... (3 Replies)
Discussion started by: nithinankam
3 Replies

5. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

6. Shell Programming and Scripting

Converting date DD MM YYYY to DD MON YYYY

Hello, I am writing a script that parses different logs and produces one. In the source files, the date is in DD MM YYYY HH24:MI:SS format. In the output, it should be in DD MON YYY HH24:MI:SS (ie 25 Jan 2010 16:10:10) To extract the dates, I am using shell substrings, i.e.: read line ... (4 Replies)
Discussion started by: Adamm
4 Replies

7. Shell Programming and Scripting

change date format from yyyy/mm/dd to dd/mm/yyyy

(Attention: Green PHP newbie !) I have an online inquiry form, delivering a date in the form yyyy/mm/dd to my feedback form. If the content passes several checks, the form sends an e-mail to me. All works fine. I just would like to receive the date in the form dd/mm/yyyy. I tried with some code,... (6 Replies)
Discussion started by: keyboarder
6 Replies

8. Shell Programming and Scripting

converting the date field from dd/mm/yyyy to yyyy/mm/dd

How to convert the date field from dd/mm/yyyy to yyyy/mm/dd in unix my script will generate text file which have two fields one is date and another is name of the server for example this is sample date which I have to sort based on older to newer date the problem is when I found out sort will... (4 Replies)
Discussion started by: pareshan
4 Replies

9. Shell Programming and Scripting

Change Date from dd-mmm-yyyy to mm/dd/yyyy

I want to change a date from format dd-mmm-yyyy to mm/dd/yyyy. Is there a way to do this with sed or do you have to write a case statement to convert JAN to 01? Thanks (9 Replies)
Discussion started by: stringzz
9 Replies

10. Shell Programming and Scripting

Date Vadidation in YYYY-MM-DD

Date Vadidation in YYYY-MM-DD Hi , Please, Help me in validating given date that is passed in arg as YYYY-MM-DD. It should cover check 1 <= DD <= 31 and 1 <= MM <= 12 for each mm check 1 <=DD<= {28,30,31} (depending) for someYYYY and MM== 02 check 1 <= dd <= 29 I the... (1 Reply)
Discussion started by: itsmehihihi
1 Replies
Login or Register to Ask a Question