0

This is my code and the output is right after that...

$PDate = $row['PDate'];  
//row is tapping into ms-sql date field. 
//and the ms-sql data field has a value like this for the PDate; 
//07/12/2001
$PDate = $PDate->date;
echo "<h1>[", $PDate , "]</h1>";
echo "<h1>[", var_dump($row['PDate']) , "]</h1>";
echo "<h1>[", serialize($row['PDate']) , "]</h1><hr>";

the output is as follows. And my question is embedded in the output.

[]      ??? WHY IS THIS BLANK? WHY IS THIS NOT 2001-12-07 00:00:00? 

[object(DateTime)#3 (3) { ["date"]=> string(19) "2001-12-07 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(19) "America/Los_Angeles" } ]

[O:8:"DateTime":3:{s:4:"date";s:19:"2001-12-07 00:00:00";s:13:"timezone_type";i:3;s:8:"timezone";s:19:"America/Los_Angeles";}]

2 Answers 2

1

The results of var_dump indicate that you're working with a DateTime object. If you want the date in a format that it can be transmitted to output or another database, you'd probably want to try working with $PDate (or $row['PDate']) as a DateTime object.

For instance:

echo $PDate->format("Y-m-d")."\n";
Sign up to request clarification or add additional context in comments.

Comments

0

$PDate stores the result from the table. So why do you redefine the variable to a variable in an object that doesn't exist. Have you tried just using $row['date'] instead of assigning it to $PDate?

1 Comment

If I do that I get this at the time insert; Catchable fatal error: Object of class DateTime could not be converted to string in sql.php on line 379

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.