PHP: DATETIME Help I know there's ample information about datetimes on the internet but I'm having trouble using what I've been seeing. I have a calander control hooked up to a text box. It takes it in the form 15/11/2010 (british). I use it to query datetime fields in a SQL server db in the format 15/11/2010 00:00:00. After the capture the dates on postback I pass the values onto my method that attempts to convert the text into time format. When I
undefined
PHP Datetime with MySQL datetime I want to ask about change a datetime value of PHP with datetime value from MySQL data. I have try to do this at PHP: $sitgl = date('Y-m-d', strtotime(2012-01-12)); $sijam = date('H:i:s', strtotime(13:00:00)); $awal = $sitgl.' '.$sijam; $awal2 = date('Y-m-d H:i:s', strtotime($awal)); $debrangkat = strtotime($awal2); And I'm trying to convert same datetime at MySQL like this (convert it to seconds): SELECT date_start_book, time_start_book, (TO_DAYS(CAST(date_start_book AS DATE))*86400) + TIME_TO_SEC(CAST(time_start_book AS TIME)) FROM `t_request_queue` WHERE `request_id` = '1301-0087' which is
undefined
PHP DateTime issue I've run into something notable. For some reason when adding a dateinterval with only minutes set in it makes it add 67 years. $wTime = new DateTime("2011-05-17 01:54:56 +0000"); echo $wTime->format("d/m/Y H:i:s\n"); $wTime->add(new DateInterval("P810M")); echo $wTime->format("d/m/Y H:i:s"); The result is: 17/05/2011 01:54:56 17/11/2078 01:54:56 I can't see where I'm doing anything wrong. Is this a bug in the DateTime object, or is something off with my code? I've run into annoying bugs with it in the past. I am running
undefined
PHP DateTime Update I'm using PHP > 5.3 and i have a question in respect of DateTime: First i'm not able to use: $date = new DateTime('2012-06-08 00:00:00'); $t = $date->createFromFormat('Y/m/d', '2012-06-11 23:59:59'); I get the following error message: Call to undefined method DateTime::createFromFormat() I can use other function in that class. The second thing i'm puzzled about how to update the object initial date, or do i have to create a new object? Answer: createFromFormat is a static method of DateTime so you
undefined
PHP DateTime for .NET Developers PHP's DateTime class has the two methods add() and sub() to add or subtract a time span from a DateTime object. This looks very familiar to me, in .NET I can do the same thing. But once I tried it, it did very strange things. I found out that in PHP, those methods will modify the object itself. This is not documented and the return value type indicates otherwise. Okay, so in some scenarios I need three lines
undefined
Modify microseconds of a PHP DateTime object I have a PHP DateTime object with microseconds created as follows: $time = microtime(true); $microseconds = sprintf('%06d', ($time - floor($time)) * 1000000); $dt = new DateTime(date('Y-m-d H:i:s.' . $microseconds, $time)); How can I modify the microseconds value of $dt, without creating a completely new DateTime instance? Answer: You can't. There are three methods that can modify the value of a DateTime instance: add, sub and modify. We can rule out add and sub immediately because they work in terms of a DateInterval which does not have sub-second precision. modify accepts
undefined
Modifying a php DateTime object I have a question respect of the proper way to modify a php DateTime object.at the present time , I'm doing something like: $origEvent = new DateTime(...); $newEvent = new DateTime(...); $someOtherEvent = new DateTime(...); //get the time difference between the orignal event and the edited event $diff = $origEvent->diff($newEvent); $someOtherEvent->add($diff); Using the DateTime::add() method seems to work whether we are adding or subtracting time from $someOtherEvent. Is this the correct way to do this? I know there is DateTime::sub() used for subtracting