Date to epoch problem

Hi all!

I have a "simple" problem:

I want to convert a date and time string (YYYYMMDDhhmmss) to epoch (unix time) in a shellscript.

I want to use the "date/time" string as an input to the script, eg:
scriptname.sh 20090918231000 and get the epoch format echoed out.

Is there an easy way to do this, I have search for it with no luck.

Thanks in advice

Condmaster

This may help you !

date --date '20090918 23:10:00' +%s

Thank you for the answer!

But if I use that format I had to convert "my" datetime-string before
converting it to unixtime (probably no issue).

I'm reading those datetime formats from a XML-file with a script
and convert them so they fit in my MySQL db.

I don't understand the last post, but, if the GNU date program is not available,
you could use somethig like this:

perl -MTime::Local -le'       
    @dt = shift =~ /(\d{2})/g;
    print timelocal $dt[6], $dt[5], $dt[4], $dt[3], $dt[2] - 1,
      ( join "", @dt[ 0 .. 1 ] ) - 1900
  ' <input> 

For example:

% perl -MTime::Local -le'       
@dt = shift =~ /(\d{2})/g;
print timelocal $dt[6], $dt[5], $dt[4], $dt[3], $dt[2] - 1,
  ( join "", @dt[ 0 .. 1 ] ) - 1900
  ' 20090918231000
1253308200