troubleshooting Question

What is being returned when you invoke the DateTime class?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
PHP
6 Comments1 Solution79 ViewsLast Modified:
Here's what I understand:

The DateTime class returns a date. Is it a superglobal? I get the impression that it's systemic, so what's the term you use to describe it?

When you invoke the DateTime class, what is being returned? If I do this:

$date = new DateTime();
//echo $date->format("Y-m-d");
echo $date;

I get an error that says the object of class DateTime could not be converted to a string. That tells me that DateTime by itself has to massaged in order for it to be used programmatically. From what I can tell, you have to format it in order for it to resonate as accurate syntax.

I've looked at the manual, but I'm still coming up short. I'm working in a .NET shop and I'm seeing several instances where some well meaning programmers have invoked the DateTime class, but they've not formatted it correctly which has led to several errors. I want to be able to explain why it's failing in conjunction with coding it correctly.

So, what is the DateTime class and why is it that you have to format it in order to be able to echo it / use it in other functionality?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros