Convert DateTime to String PHP I before researched a lot of Website on how can i convert PHP DateTime object to String. I always see "String to DateTime" and not "DateTime to String" PHP DateTime can be echoed, but what i want to process my DateTime with PHP string functions. Now my question is how can I make PHP dateTime Object to a string starting from this kind of codes <?php $dts = new DateTime(); //this returns the current date time echo strlen($dts); ?> Solution:
undefined
Convert javascript datetime into php datetime I want to change javascript date Mon Jun 23 2014 16:17:05 GMT+0530 (India Standard Time) into PHP datetime. I tried echo date('Y-m-d h:i:s', strtotime($expire_time)); where $expire_time is Mon Jun 23 2014 16:17:05 GMT+0530 (India Standard Time) but it is giving1970-01-01 12:00:00. Answer : (India Standard Time) causes the trouble with parsing, so you need to remove it from the string before calling date(). You can use something like: $expire_time = 'Mon Jun 23 2014 16:17:05 GMT+0530 (India Standard Time)'; $expire_time = substr($expire_time, 0, strpos($expire_time, '(')); echo
undefined
Convert a Javascript Date format to desired PHP format How can we change Wed Jun 09 2010 which is returns from a javascript function and get in a php script.I need to convert this date format to 2010-06-09.Thanks Answer: <?php $jsDateTS = strtotime($jsDate); if ($jsDateTS !== false) date('Y-m-d', $jsDateTS ); else // .. date format invalid
undefined
PHP DateTime class Namespace I'm use the symfony2 framework and I want to use the PHP's DateTime class (PHP version is 5.3). Here the statement: namespace SDCU\GeneralBundle\Entity; class Country { public function __construct(){ $this->insertedAt = new DateTime(); } } But, when execute this constructor, I get an error saying that there's no "SDCU\GeneralBundle\Entity\DateTime" class. I've been searching around for DateTime's namespace but with no success... any idea? Answer: DateTime is in the global namespace, and as "classnames always resolve to the
undefined
Should I use field 'datetime' or 'timestamp'? Would you suggest using a datetime or a timestamp field, and why (using MySQL)? I'm working with PHP on the server side. solution: Timestamps in MySQL generally used to track change to records, and are often updated each time the record is changed. If you want to store a specific value you should use a datetime field. If you meant that you want to decide linking using a UNIX timestamp or a native MySQL datetime field,
undefined
Convert from MySQL datetime to another format with PHP I have a datetime column in MySQL. How can I convert it to the display as mm/dd/yy H:M (AM/PM) using PHP? Solution : To convert a date retrieved from MySQL into the format requested (mm/dd/yy H:M (AM/PM)): // $datetime is something like: 2014-01-31 13:05:59 $time = strtotime($datetimeFromMysql); $myFormatForView = date("m/d/y g:i A", $time); // $myFormatForView is something like: 01/31/14 1:05 PM Refer to the PHP date formatting options to adjust the format. http://stackoverflow.com/questions/136782/convert-from-mysql-datetime-to-another-format-with-php/5367048#5367048
undefined
Facebook API - How do I get a Facebook user's profile image through the Facebook API (without requiring the user to “Allow” the application) I'm working on a CMS that fetches a user's profile image from their Facebook URL (that is, http://facebook.com/users_unique_url). How can I accomplish this? Is there a Faceboook API call that fetches a user's profile image URL without the user needing to Allow the application? Answer: Simply fetch the data through this URL: http://graph.facebook.com/userid_here/picture Replace userid_here with id of the user you want to get the photo of. You can