PHP if date equals then
Question by huddds
Hi I’m trying use a datepicker on a field I have. I’m trying to set the date field up so the user can only edit this field if the date value in the database is set to deafault (0000-00-00). If there is a value that’s not equal to default I want to show the date created.
Here’s the code I have attempted:
if( $post['Date'] = var_dump(checkdate(00, 00, 0000))){
echo "<input type="text" class="datepicker" name="pDate" style="border:#000099; margin:10px;" value="";
echo $post['Date'];
echo ""> <input id="start_dt" class="datepicker">";
}
if( $post['Date'] != var_dump(checkdate(00, 00, 0000))){
echo "<span>date created: </span>";
echo $post['Date'];
}
It’s not working atm so any help or a point in the right direction would be great.
Please also take into account I haven’t added any proper styling so I’m only after help with the functionality.
Many thanks.
Answer by Starx
var_dump()
is used for debugging purpose rather than inside conditional expression. Next, using =
assigns the values not checks for them. You are assigning the values of var_dump()
results to $post['Date']
So change them to ==
You should be trying to to something like this
if( $post['Date'] == checkdate(00, 00, 0000)){
echo "<input type="text" class="datepicker" name="pDate" style="border:#000099; margin:10px;" value="".$post['Date']"">";
echo "<input id="start_dt" class="datepicker">";
} else {
echo "<span>date created: </span>";
echo $post['Date'];
}