in reply to sql datetime value with today

If you're retrieving your SQL DATETIME as a string, use something like Time::Piece's strptime or DateTime::Format::Strptime to convert it to a better representation, then use the provided methods to compare.

use DateTime (); use DateTime::Format::Strptime (); print DateTime::Format::Strptime ->new(pattern => '%Y-%m-%d %H:%M:%S.%3N') ->parse_datetime('2012-01-31 00:00:00.000') ->truncate(to=>'day') ->compare( DateTime->today ); # compare returns 0 if they're equal

That might seem like a little overkill for what could be done with a simple string comparison of two dates in the same format, but can be very useful once time zones or other DateTime features get involved.

Replies are listed 'Best First'.
Re^2: sql datetime value with today
by fionbarr (Friar) on Sep 19, 2014 at 19:53 UTC
    thanks....