Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Converting localtime to SQL format

by blazar (Canon)
on Mar 30, 2005 at 08:41 UTC ( [id://443372]=note: print w/replies, xml ) Need Help??


in reply to Converting localtime to SQL format

In addition to the good answers you already got, I think it is worth reminding that most perl functions return different values according to the context. In this case it wouldn't be too hard to roll your own(TM) solution:
my $time = do { my ($s,$m,$h,$D,$M,$Y)=localtime; $Y+=1900; $M++; "$Y-$M-$D $h:$m:$s" };
UPDATE: I added $M++ which was not not there as per crenz's warnings.

Replies are listed 'Best First'.
Re^2: Converting localtime to SQL format
by crenz (Priest) on Mar 30, 2005 at 08:55 UTC

    You provide a good reason to rather use Posix::strftime(): Your solution is wrong since the month is zero-based and you forgot to increment the month.

      You provide a good reason to rather use Posix::strftime(): Your solution is wrong since the month is zero-based and you forgot to increment the month.
      Indeed. Mine was more of an example especially aimed at reminding of different contexts.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://443372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-26 03:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found