Re: Last Second of Day for the given date?
[email protected] (Dave Rolsky)
| Newsgroups | perl.datetime |
|---|---|
| Message-ID | <[email protected]> |
On Thu, 12 Mar 2009, Bill Moseley wrote: > Is there a canonical approach, or is it something like: > > $dt->add( days => 1 )->truncate( to => 'day' )->subtract( seconds => 1 ); That should work fine, _but_ if you're not in the floating timezone that could land you on "second 60" every once in a while, and your dbms may not like it. > Here's the ugly part: > > The deal is I have a web form where start and end dates are entered, > but in the database the column is a timestamp. Typically, the > smallest interval is an entire day, but want to retain the ability to > use a custom time within the day. > > So, instead of truncating in the database select (which would prevent > using a custom start or end time of day) the plan is to truncate the > DateTime objects before storing in the database. > > So, in this form, the smallest interval possible is one day, so if the > same date is entered for both start and end then the interval is the > entire day. > > Yes, a bit convoluted. If the unit of interval is days, I'd suggest simply defining an internval as "from X (inclusive) to Y (non-inclusive)". That way both X and Y can be plain old dates. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/