Ronald
Ronald

Reputation: 557

Javascript PHP String not returning desired results

I am using this javascript or PHP to convert a database field into a string so that I can sort on that column, however when the value of the database is null - the sorting is screwed up because I get a weird value around 1970 for the year

Does anyone know how to fix this ??

$movie_str = date('Ymd', strtotime($row['CD_MOVIE']));

Upvotes: 0

Views: 47

Answers (1)

Maxime Savard
Maxime Savard

Reputation: 128

Depending on what you want to do when your value is null, you could do something like

$val = $row['CD_MOVIE'];
$movie_str = (!is_null($val)) ? date('Ymd', strtotime($val)) : "0";

Upvotes: 3

Related Questions