[thelist] PHP Date question

Max Schwanekamp lists at neptunewebworks.com
Wed Dec 13 10:54:42 CST 2006


Casey Crookston wrote:
> $this->Search->Fields["DateStart"]->Value .= " 12:00:00 AM";
> $this->Search->Fields["DateEnd"]->Value .= " 11:59:59 PM";
> So, the data for the report runs from 12:00:00 AM on the start date
> selected by the user to 11:59:59 on the end date selected by the user.
> Trouble is, their bank/merchant account is several time zones off.  We
> need to adjust the times to run from 8:00:00 PM of the PREVIOUS DAY (one
> day before the user selects as the start date) to 7:59:59 PM of the end
> date.  Setting the end time to 7:59:59 is simple enough, but I'm not
> sure how to adjust the start date back one day.
> $date-> Fields["DateStart"]->modify("-1 day");
> But that doesn't work.  I'm sure it's simple, but I know nothing about
> PHP. Thanks,

If you absolutely must work with date strings instead of unix timestamps 
(much easier in most cases), then strtotime() is your friend.
<?php
$mydate = '12/13/2006 12:00:00 AM';
/* adjusted timezone is server time + -4 hours */
$tzAdjust = -4;
/* multiply the timezone adjustment by 3600 seconds (1 hour)
    and add it to the server time */
$adjustedTimestamp = strtotime($mydate) + ($tzAdjust * 3600);
/* re-format it as a date string*/
$adjustedDate = date('m/d/Y H:i:s A',$adjustedTimestamp);
?>

But again, it's way easier to just convert user inputted date strings 
into unix timestamps and work with those, since they're integers.

-- 
Max Schwanekamp
NeptuneWebworks.com
541-517-9064



More information about the thelist mailing list