Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-07-2012, 04:15 PM   PM User | #1
Poligu
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Poligu is an unknown quantity at this point
Basic PHP and Objects

Hi,

I consider myself a decent programmer. However, I often run into some problems when I try to learn new things. Right now, I am simply trying to take a date and output in GMT format. To do this, I was at php.net and found the example shown below. However, neither the object style nor the procedural style work for me.

Why is it that my server produces and error for each method?

$date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009');
echo $date->format('Y-m-d');

$date = date_create_from_format('j-M-Y', '15-Feb-2009');
echo date_format($date, 'Y-m-d');


Thanks
Poligu is offline   Reply With Quote
Old 09-07-2012, 04:34 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Make sure your error reporting is enabled:
PHP Code:
ini_set('display_errors'1);
error_reporting(E_ALL); 
Or check the error logs; does it show any error on that call to createFromFormat?
Fou-Lu is offline   Reply With Quote
Old 09-07-2012, 04:54 PM   PM User | #3
Poligu
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Poligu is an unknown quantity at this point
Thanks

It tells me that the method DateTime::createFromFormat() is undefined
Poligu is offline   Reply With Quote
Old 09-07-2012, 05:00 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Then your PHP version is too old to use DateTime::createFromFormat.
The format you have here though passes gnu specifications for datetime string formats. You can simply replace the line for create from format with $date = new DateTime('15-Feb-2009');
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 PM.


Advertisement
Log in to turn off these ads.