Roderick A. Anderson wrote:
Short story usng the truncate method on a datetime object that was created
with a format destroys/removes the format -- forever.

On Thu, 4 Aug 2005, Eugene van der Pijll replied:
That's a bug. DT::truncate() copies the locale and the timezone, but
should also copy the formatter.

Not a bug. Strptime is a ::Format module, all it does is takes a string and returns a DateTime.

However, once you have your formatter object, it's as simple as calling
   $formatter->format_datetime( $dt );


So, putting the whole thing together you get this:
my $filename = $formatter->format_datetime(
   $formatter->parse_datetime('200508050801')
      ->truncate( to => 'month' )
);
# 200508010000



Roderick A. Anderson wrote:
On another note I was reading another thread in the archives and noted
->strftime ( which must have slipped right by me in the docs ) and this
does what I need with a single DT object. A filename prefix, and a _real_ date and time.

Slipped past you in both the DateTime docs and the Strptime docs as it's discussed in both .. :)

Cheers!
Rick Measham

Reply via email to