Jump to content

Recommended Posts

Posted

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!
 
Posted

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
}
Posted

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

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
  • Recently Browsing   0 members

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