Categories > TinyButStrong general >

print a mysql datetime field

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Tobi
Date: 2006-01-14
Time: 23:51

print a mysql datetime field

Hi,
to save datas i used the mysql field "datetime"
It provides the formal: "yyyy-mm-dd hh:mm:ss"
With the TBS function: [...fld;frm='dd.mm.yyyy hh:nn'] I am able to reform it.
But sometimes only the date is defined. In this case is 00:00 displayed.
Is it posible to hide the 00:00 in this case?
By: Skrol29
Date: 2006-01-16
Time: 12:11

Re: print a mysql datetime field

Hello Tobi,

Parameter 'frm' cannot do such conditional format.
But you can code your own formating using a custom function and parameter 'onformat'.
By: Tobi
Date: 2006-01-16
Time: 12:32

Re: print a mysql datetime field

Could you give me an example?
By: Skrol29
Date: 2006-01-16
Time: 13:36

Re: print a mysql datetime field

Example :
HTML:
[myfield;onformat=f_custom_date]

PHP:
function f_custom_date($FieldName,&$CurrVal,&$CurrPrm,&$TBS) {
  $CurrVal = date('Y-m-d H:i',$CurrVal); // yyyy-mm-dd hh:nn
  $pos = strpos($CurrVal,' 00:00');
  if ($pos!==false) $CurrVal = substr($CurrVal,0,$pos);
}
By: Tobi
Date: 2006-01-16
Time: 18:51

Re: print a mysql datetime field

Do I have to place the function in the class or someware in the php file?
By: Skrol29
Date: 2006-01-17
Time: 14:16

Re: print a mysql datetime field

No need to update the class.
Just past the function in your main script. In the same script that use $TBS.
You can past it even at the end of the script.