Page 1 of 1

blank dates save as current date

Posted: 2018-05-08 19:43
by D Oliveira
Hello, my issue is that when I save a record with a blank date it gets the current date. I use fpdf to export a 'work order' file, whenever I put a specific date it works fine, but when I leave it blank it gets the current date (today's date). Anyone can shed some light on how to solve this?

https://ibb.co/eq0ddn
https://ibb.co/egQGW7
https://ibb.co/dmx24S

Re: blank dates save as current date

Posted: 2018-05-08 20:40
by pbottcher
Hi,

are you using any hooks to check on the date? PHP or JS?
Can you check that in the form you are submitting the date is empty and in the DB the date is set to the current date?

Re: blank dates save as current date

Posted: 2018-05-09 15:46
by D Oliveira
i forgot to add the .php file that handles the fdpf, it think that might be it, I think checking the lenght first might solve the issue

Code: Select all


$date1 = $gwoid['gdatesched'];
$date =date_create($date1);

$pdf->SetY(29.2);
$pdf->SetX(137);
$pdf->Cell(90 ,5,date_format($date,"M/d"),0,1);


Re: blank dates save as current date

Posted: 2018-05-09 17:21
by pbottcher
Hi,
ok, but now it would be necessary to understand what/how your $gwoid['gdatesched'] is filled. If it is empty, this is what I assume, date_create will create the date object as the current date. So you should check what is in there and apply your logic accordingly.

Re: blank dates save as current date

Posted: 2018-05-09 19:25
by D Oliveira
thanks that worked

Code: Select all

$date1 = $gwoid['gdatesched'];

if (strlen($date1) > 2){
    $date =date_create($date1);

$pdf->SetY(29.2);
$pdf->SetX(137);
$pdf->Cell(90 ,5,date_format($date,"M/d"),0,1);
} 
else 
{
    //echo "should be blank.";
}