On Mon, 2007-08-13 at 00:25 -0700, Alan wrote: > On Mon, Aug 13, 2007 at 02:43:04PM +0800, Ow Mun Heng wrote: > > Been struggling with a new script I'm porting over from bash because > > perl's DBI is much more elegant than my previous usage of sqsh. > > > > I'm having trouble converting from a datetime into a unix epoch > > timestamp. > > > > under bash, this is done. > > > > date = YYYY-MM-DD HH:MM:SS > > epoch_date = date -d "$date" +%s > > > > $date > > Mon Aug 13 14:39:48 MYT 2007 > > $date -d "2007-08-13 14:39:48" +%s > > 1186987188 > > > > Under perl, I have no idea how this can be achieved. > > Neither localtime, timelocal or AFAICT, DateTime can achieve this > > easily. > > Maybe I'm confusing what you're looking for, but a look at 'perldoc > DateTime' shows that the perl DateTime module has a 'epoch' function: > > $epoch_time = $dt->epoch; > # may return undef if the datetime is outside the range that is > # representable by your OS's epoch system.
Yepp.. It's fine to get the current time's epoch via DateTime. What I want is actually to convert from a datetime into an epoch.. eg: User supplied Datetime = "2007-08-13 14:39:48" I want that Datetime converted into an Epoch Format. > > As another OOT suggestion, check out Class::DBI as something even more > elegant than DBI. I've been using it for the last year or so and LOVE > it's simplicity and OO-ness compared to DBI. Will loook into it, _after_ I settled all these date/time issues which is driving me a bit nutty. -- [EMAIL PROTECTED] mailing list