eldan88 Posted April 5, 2014 Share Posted April 5, 2014 Hey Guys. I am fairly new to using the DateTIme Object and trying to familiarize myself with it. There is two things that I am really confused about First, when I try to pass it a string in the constructor like "tomorrow" it throws me a "Catchable fatal error: Object of class DateTime could not be converted to string". Below is the code I am using $date = new DateTime('now'); echo $date; The second thing I am confused is how use their constants such as const string ATOM = "Y-m-d\TH:i:sP" ; const string COOKIE = "l, d-M-y H:i:s T" ; const string ISO8601 = "Y-m-d\TH:i:sO" ; Are they predefined? Any help would be really appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/287529-need-help-using-datetime-object/ Share on other sites More sharing options...
Solution eldan88 Posted April 5, 2014 Author Solution Share Posted April 5, 2014 Nevermind. This tutorial i was reading online did not explain it correctly. Now I now why it wasn't working. Quote Link to comment https://forums.phpfreaks.com/topic/287529-need-help-using-datetime-object/#findComment-1475008 Share on other sites More sharing options...
requinix Posted April 5, 2014 Share Posted April 5, 2014 1. echo $date;That's where the problem was. You have to use something like $date->format(...) to get output. 2. Yes, they are predefined. Quote Link to comment https://forums.phpfreaks.com/topic/287529-need-help-using-datetime-object/#findComment-1475009 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.