Date conversion from Standard/given format to seconds/epoch

I am trying get time difference of two dates in secs. Initially I want to convert a standard date format to epoch for two dates and then subtract the two epoch dates.
Example :

date -d "2007-09-01 17:30:40" '+%s'

But this gives me below error

date: illegal option -- d
Usage: date [-u] [+Field Descriptors]

OS: AIX 5.3.0.0

Thanks in advance

I got this in Bash on linux:

echo "$(date +'%s' -d 2007-09-02)/86400"-"$(date +'%s' -d 2007-09-01)"/86400 | bc

1

Seconds... I don't know... but I enjoyed the exercise.

more accurately (using bash)

echo $(date --date='2007-09-01 17:30:00' +%s)/60-$(date --date='2007-09-01 18:30:00' +%s)/60 | bc

more elegant or appropriate solutions may also be offered.

Sorry for late reply.

When I execute on my bash I get below errors

echo "$(date +'%s' -d 2007-09-02)/86400"-"$(date +'%s' -d 2007-09-01)"/86400 | bc
Invalid character in date/time specification.
Usage: date [-u] [+Field Descriptors]
Invalid character in date/time specification.
Usage: date [-u] [+Field Descriptors]
syntax error on line 1 stdin

can you help me on this? Is it something to do with my bash?

Not all date command offers you all options.

You may have to use some script ( probably perl script ) to do the conversion ....

use DateTime;
$dt = DateTime->new( year => 1974, month => 11, day => 30, hour => 13, minute => 30,      second => 0, nanosecond => 500000000, time_zone => 'Asia/Taipei' ); 
$epoch_time  = $dt->epoch; 

Refer Perl Epoch Converter Routines

If you have possible to use ksh93, then builtin printf using:

epoc=$(printf "%(%s)T" "2010-10-24 00:00:00")

Or using bash, ksh, dash, ... something like

oifs="$IFS"  
JulianDate() 
{  
IFS="-"  
array=($1)  
IFS="$oifs"  
scale=0  
d=${array[2]}  
m=${array[1]}  
y=${array[0]} 
echo $((d-32075+1461*(y+4800+(m-14)/12)/4+367*(m-2-(m-14)/12*12)/12-3*((y+4900+(y-14)/12)/100)/4 )) 
}  

fromdate=$( JulianDate 2011-04-01 ) 
# ISO yyyy-mm-dd 
todate=$( JulianDate 2011-05-04 )  
diff=$((todate - fromdate)) 
echo $diff

ksh93 version in AIX 5.3.0.0 is M-12/28/93 and dosn't support %T with printf

You could use a simple perl script:

$ perl -e 'use Time::Local; print timelocal(0,0,0,$ARGV[2], $ARGV[1]-1, $ARGV[0]);' 2007 09 01
1188568800