Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Postgres time stamp calculations 1

Status
Not open for further replies.

kungphu

Programmer
Joined
May 23, 2006
Messages
13
Location
GB
Hi perl, newbie here, I am working on a legacy system which has been developed in perl and postgres. I am trying to get time stamp values from the db and use them for calculations.

I do the appropriate select * from table name, and then bind the values of the columns to perl variables. The time column I want is called start and I can output is value as a print statement. The output looked like this

2006-04-18 13:21:53

What i want to do is strip the above information into vairables and then do calculations based on the time.

I tried this code
Code:
my ($year,$month,$day,$hour,$min,$sec) = ( $start =~ /^ (\d\d\d\d) (\d\d) (\d\d) (\d\d) (\d\d) (\d\d) /);

When I try the above and do a print statement on one of the variables I get a blank result. What do I need to alter toget the result I need?
 
There are punctuation characters in the string, but nothing to match them in your regex. You would need instead something like:
[tt]
my ($year,$month,$day,$hour,$min,$sec) =
$start=~/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/;
[/tt]
 
Thanks Tony that has worked a treat. [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top