save time in the Postgresql database

2

In the application I inform the start and end time of the activity, and save this information in the database.

Follow Query:

$status = $_GET['status'];
$intervalo = $_GET['intervalo'];
$dataini = $_GET['horainicio']."<br>";
$horainicio = date('H:i:s',$dataini);
$datafim = $_GET['horafinal']."<br>";
$horafinal = date('H:i:s',$datafim);
$qtdtentativas = $_GET['qtdtentativas'];
$destino = $_GET['destino'];
$skill = $_GET['skill'];
$pacing = $_GET['pacing'];
$prefixo = $_GET['prefixo'];



$query = sprintf("update bettaivr.public.ivr_campanha set status = %d,horainicio = %d,horafinal = %d, intervalo = %d, pacing = %d, qtdtentativas = %d  where id = %s",
$status,$horainicio ,$horafinal ,$intervalo, $pacing, $qtdtentativas,$campanha);

Although I can not save the time in the database, it always returns 0. How can I save this time in the bank?

Error flagged when executing query:

Problem with query update bettaivr.public.ivr_campanha set status = 0, horainicio = '0', endtime = '0', interval = 20, pacing = 1, qtdtentatives = 5 where id = 4

    
asked by anonymous 15.06.2018 / 17:56

1 answer

2

Your problem is here:

$horafinal = date('H:i:s',$datafim);
$horainicio = date('H:i:s',$dataini);

try this:

$horafinal = date('H:i:s',strtotime($datafim));
$horainicio = date('H:i:s',strtotime($dataini));

And use the query like this:

$query = "
    UPDATE 
        bettaivr.public.ivr_campanha 
    SET 
        status = '$status',
        horainicio = '$horainicio',
        horafinal = '$horafinal',
        intervalo = '$intervalo',
        pacing = '$pacing',
        qtdtentativas = '$qtdtentativas'
    WHERE id = '$campanha'
";
  • Some documentation references on date and strtotime :
  

strtotime - Interprets any date / time description in English text in Unix timestamp

     

date - Format the date and local time. Returns a string according to the format string entered using the integer timestamp informed

    
15.06.2018 / 18:27