All In One Script



PHP,HTLM,CSS,Jquery,AJAX,Javascript and etc doubts and sample codes

  • Home
  • Javascript
  • PHP
  • CSS
  • SQL/MYSQL

PHP DateTime issue

by Blogger 3:03:00 AM Issue PHP PHP DateTime

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 the latest version of PHP (5.3.6) built from source on Mac OS X 10.6

Answer:

Check the docs, you're adding 810 months (~67 years). Try PT810M


http://stackoverflow.com/questions/6039278/php-datetime-issue
READ MORE
SHARE :

Search This Blog

Followers

  • Popular
  • Recent
  • Comments
    Serving XHTML and self-closing tags
    How to efficiently iterate over each Entry in a Map?
    Get first key in a (possibly) associative array?
    How to avoid Java code in JSP files?
    Does finally always execute in Java?
    Solved : curl_init() function not working in Ubuntu
    Why does this code using random strings print “hello world”?
    In Java, difference between default, public, protected, and private
    How can I make the cursor a hand when a user hovers over a list item?
    Length of a JavaScript object

Instagram

About

Popular Posts

  • Serving XHTML and self-closing tags
    Serving XHTML and self-closing tags I am trying to follow the xhtml 1.0 strict standard as I am creating my website. Right now, validat...
  • How to efficiently iterate over each Entry in a Map?
    How to efficiently iterate over each Entry in a Map? If I have an object implementing the  Map  interface in Java and I wish to iterate...
  • Get first key in a (possibly) associative array?
    Get first key in a (possibly) associative array? What's the best way to determine the first key in a possibly associative array? My...
  • How to avoid Java code in JSP files?
    How to avoid Java code in JSP files? I'm new to Java EE and I know that something like the following three lines <%= x + 1 %...
  • Does finally always execute in Java?
    Does finally always execute in Java? I have a try/catch block with  return s inside it. Will the finally block be called? For example...
  • Solved : curl_init() function not working in Ubuntu
    Solved : curl_init() function not working in Ubuntu  Here solved the error  Fatal error: Call to undefined function curl_init() ...
  • Why does this code using random strings print “hello world”?
    Why does this code using random strings print “hello world”? The following print statement would print "hello world". Could a...
  • In Java, difference between default, public, protected, and private
    In Java, difference between default, public, protected, and private In Java , are there clear rules on when to use each of access modifi...
  • How can I make the cursor a hand when a user hovers over a list item?
    How can I make the cursor a hand when a user hovers over a list item? I've got a list, and I have a click handler for its items: ...
  • Length of a JavaScript object
    Length of a JavaScript object If I have a JavaScript object, say var myObject = new Object (); myObject [ "firstname" ] ...

statcounter



statcounter



Template Created By ThemeXpose & Blogger Templates