Perhaps this has already happened to some of you...
I'm using xCRUD v.1.7.15.
I'm having problems with fields of type datetime. When I create a record the current date and time are correctly recorded in the same field, but when I edit an existing record the time is set to zero.
Since we are in Italy, I set it like this in the xcrud_config.php file:
To set the value of a record at the current moment I use statements like
which work correctly, the value is correctly recorded and displayed, but the time is reset to zero when the record is modified later, i.e. every time I update it.
I tried with some callbacks, for example in the functions.php file I added this function:
which I attempted to invoke before or after the upgrade;
this didn't work, like when fetching the value of type datetime existing in the record only the date was extracted.
Indeed,I also tried to store the existing value before the update in a session variable using these instructions in a function associated with the before_update event:
but when i try to insert this value via another function
associated with the after_update event
it turns out that the SQL instruction already carries the value of the date only, without the time (which was there before):
From this I think I can deduce that it is the command
to extract the already truncated data.
Anyone have suggestions?
I'm using xCRUD v.1.7.15.
I'm having problems with fields of type datetime. When I create a record the current date and time are correctly recorded in the same field, but when I edit an existing record the time is set to zero.
Since we are in Italy, I set it like this in the xcrud_config.php file:
Code:
// date
public static $date_first_day = 1; // 0 - Sunday, 1 - Monday etc. Uses in datepicker and search ranges
public static $date_format = 'dd/mm/yyyy'; // jqueryui date format
public static $time_format = 'HH:mm:ss'; // jqueryui time format
public static $php_date_format = 'd/m/Y'; // php date format
public static $php_time_format = 'H:i:s'; // php time format
To set the value of a record at the current moment I use statements like
Code:
$xcrud->pass_default('data_ticket',date('Y-m-d H:i:s'));
which work correctly, the value is correctly recorded and displayed, but the time is reset to zero when the record is modified later, i.e. every time I update it.
I tried with some callbacks, for example in the functions.php file I added this function:
Code:
function data_ticket($postdata, $primary, $xcrud){
$postdata->set('data_ticket', date('Y-m-d H:i:s', strtotime($postdata->get('data_ticket'))));
}
which I attempted to invoke before or after the upgrade;
this didn't work, like when fetching the value of type datetime existing in the record only the date was extracted.
Indeed,I also tried to store the existing value before the update in a session variable using these instructions in a function associated with the before_update event:
Code:
$data= $postdata->get('data_ticket');
$_SESSION['data_ticket']=$date;
but when i try to insert this value via another function
associated with the after_update event
Code:
$data=$_SESSION['data_ticket'];
$q="UPDATE ticket SET data='$data' where id=$id";
$db->query($q);
it turns out that the SQL instruction already carries the value of the date only, without the time (which was there before):
Code:
UPDATE ticket SET data='2023-07-20 00:00:00' where id=46
From this I think I can deduce that it is the command
Code:
$data= $postdata->get('data_ticket');
to extract the already truncated data.
Anyone have suggestions?