chrizz Posted January 20, 2015 Posted January 20, 2015 Hey everyone, I am struggeling a little bit with a datetime field for my pages. I want to check whether a datetime field is empty or not, but with my first assumtion this is not as easy as it seems to be... :/ var_dump(empty($page->verein_datum)); var_dump($page->verein_datum); returns bool(true) int(1397253600) I am not sure if this behaviour is wanted but I try to figure out which way is the best to check if the date is set or not. Any suggestions? Thanks!
adrian Posted January 21, 2015 Posted January 21, 2015 Firstly, if var_dump($page->verein_datum); returns int(1397253600) then the field is not blank - it is set to: Fri, 11 Apr 2014 22:00:00 GMT If it is actually empty, it is as simple as: if(!$page->verein_datum) { //date field is empty } but if you want, you could also do: if(empty($page->verein_datum)) { //date field is empty } or if($page->verein_datum === '') { //date field is empty }
chrizz Posted January 21, 2015 Author Posted January 21, 2015 thanks Adrian for your suggestions. !$page->verein_datum works perfectly. I was just wondering why var_dump(empty($page->verein_datum)) returns true (= blank) and var_dump without empty returns the value as expected... perhaps it's better to stop thinking about it and enjoy coding with PW
kongondo Posted January 21, 2015 Posted January 21, 2015 Your var_dump(empty($page->verein_datum)); worked for me as expected
chrizz Posted January 21, 2015 Author Posted January 21, 2015 hm... nevermind... perhaps some weird behaviour in my xampp development environment. Thanks anyway
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now