Skip to main content
Topic: Empty date fields display current date time (Read 1665 times) previous topic - next topic

Empty date fields display current date time

Hello all,
I have some datetime fields in my db.
I use the FormatRecordField (--format_date('Y-m-d H:i:s')--) to format the dates as I need them.
It works but all fields that are empty display the current date time. Why? They should be empty.
Is there a way to format the date only on non-empty fields?
TIA
tony

 

[SOLVED]Re: Empty date fields display current date time

Reply #1
Never mind,
I solved it.
Instead of using the --FormatRecordField-- option I changed the field type from PlainText to CUSTOM and changed the code manually:

LIST
from:
Code: [Select]
 <span><?php echo $data['my_date']; ?></span>

to:
Code: [Select]
<span> <?php echo ((isset($data["my_date"]))?date('d/m/Y H:i:s',strtotime($data["my_date"])):""); ?></span>

VIEW
from:
Code: [Select]
<tr  class="td-my_date">
<th class="title"> Date: </th>
<td class="value"><?php echo $data['my_date']; ?></td>
</tr>

to:

Code: [Select]
<tr  class="td-my_date">
<th class="title"> Date: </th>
<td class="value"><?php echo ((isset($data["my_date"]))?date('d/m/Y H:i:s',strtotime($data["my_date"])):""); ?></td>
</tr>

Works fine!
HTH
Tony