-1
if(strtotime($date_in)==false){
    echo $date_in." wtf?";
}

Output:

2012-05-12 wtf?

Why does strtotime($date_in) return false?

Manse
  • 37,765
  • 10
  • 83
  • 108
szapio
  • 998
  • 1
  • 9
  • 15
  • 1
    It depends on the value on $date_in – Simon Forsberg May 15 '12 at 11:31
  • 1
    If you are checking for false, always use the `===` operator. – kapa May 15 '12 at 11:32
  • 1
    Take a look at the allowed date/time formats: http://de.php.net/manual/en/datetime.formats.php – mAu May 15 '12 at 11:32
  • You almost certainly have more characters in your input string than you think, my money is on leading/trailing non-numeric characters. Please show the *exact* output of `var_dump($date_in);` – DaveRandom May 15 '12 at 11:34
  • 2
    Using your examples from your question [it works fine for me](http://codepad.org/JLDNAOPU) - i suggest the input isnt what you think it is – Manse May 15 '12 at 11:35

2 Answers2

3

Try:

if(strtotime($date_in)===false){
    echo "[$date_in] wtf?";
}

If testing for false always use the ===. Also wrapping the $date_in variable with brackets help you see if there is any whitespace.

http://php.net/manual/en/function.strtotime.php

iambriansreed
  • 21,935
  • 6
  • 63
  • 79
2

I've tried to replicate this issue, with success, but only after I changed the default timezone to:

date_default_timezone_set('Europe/Brussels');

so, perhaps you could check your ini file, or use date_timezone_get and make sure the your settings know how to deal with the date format you're using?

Alternatively, or if the php.ini is off limits for some reason, you could look into the datetime object.

Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
  • Thx all for response it was whitespace in $date_in variable. I fill $date_in with value from database (date field in mysql). Don`t know why it returned whitespace but that was the problem. – szapio May 15 '12 at 16:35
  • 1
    damn, thought about suggesting `trim()` - perhaps check if the field in your DB is set as varchar - with spacefill? – Elias Van Ootegem May 15 '12 at 23:42