Jump to content

Check if a datetime field is empty does not work


chrizz
 Share

Recommended Posts

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!
 
Link to comment
Share on other sites

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
}
Link to comment
Share on other sites

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 :D

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...