How to get Date ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tamilmani
Forum Commoner
Posts: 39
Joined: Tue Apr 01, 2008 2:53 am

How to get Date ?

Post by tamilmani »

Hi ,

Here is my var_dump result. I need the get the date from this result . How i get this ?

Code: Select all

array(1) { [0]=>  object(stdClass)#67 (6) {
 ["number"]=>  int(21) 
["ID"]=>  int(6)
 ["Description"]=>  string(9) "Day" 
["PDate"]=>  object(DateTime)#66 (3) {
	 ["date"]=>  string(19) "2010-04-25 00:00:00"
	 ["timezone_type"]=>  int(3) 
	 ["timezone"]=>  string(13) "Asia/Calcutta" 
	} 
["pid"]=>  int(6) 
["pname"]=>  string(26) "Test" 


 } } 

Any suggestion please ?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: How to get Date ?

Post by AbraCadaver »

Code: Select all

$date = $yourvar[0]->PDate->date;
Should work.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
tamilmani
Forum Commoner
Posts: 39
Joined: Tue Apr 01, 2008 2:53 am

Re: How to get Date ?

Post by tamilmani »

Hi Dude,

There is no luck for this code. I don't get anything. Still i have this issue.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: How to get Date ?

Post by AbraCadaver »

tamilmani wrote:Hi Dude,

There is no luck for this code. I don't get anything. Still i have this issue.
Works for me. You need to have error reporting on, post your code and post the error.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
tamilmani
Forum Commoner
Posts: 39
Joined: Tue Apr 01, 2008 2:53 am

Re: How to get Date ?

Post by tamilmani »

I retrive the datas from table . I am using micrsoft sql server . PDate (field type is datetime)

Code: Select all

if (isset($result)){ if ($result!= ""){
	foreach ($result as $row)
	{
		$phid = $row->PNumber;
		$pid = $row->ID;
		$pname = $row->pname;
		$description = $row->Desc;
		$datetime = $row->PDate;  
	
	}
}}
when i print the $datetime . I am getting error message like as

Code: Select all

A PHP Error was encountered
Severity: 4096
Message: Object of class DateTime could not be converted to string

User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: How to get Date ?

Post by AbraCadaver »

Try:

Code: Select all

$datetime = $row->PDate->date;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
tamilmani
Forum Commoner
Posts: 39
Joined: Tue Apr 01, 2008 2:53 am

Re: How to get Date ?

Post by tamilmani »

I used above code . I am getting error message. Anything need to change in php.ini ????

Code: Select all

A PHP Error was encountered
Severity: Notice
Message: Undefined property: DateTime::$date
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: How to get Date ?

Post by AbraCadaver »

tamilmani wrote:I used above code . I am getting error message. Anything need to change in php.ini ????

Code: Select all

A PHP Error was encountered
Severity: Notice
Message: Undefined property: DateTime::$date
No. I can't see a problem.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply