Time validation always return false. PHP DateTime, Laravel

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Time validation always return false. PHP DateTime, Laravel



I'm trying to create a controller for validation for time variable date and time.
The problem is the code can validate the date and check in time correctly but always getting false value for check out time.
Every variable of $checkOut always ended validate as Not Valid, Wrong Check Out Time Format.


$checkOut


Not Valid, Wrong Check Out Time Format



output


function validateTime($time)
{
$d = DateTime::createFromFormat('H:i:s', $time);
return $d && $d->format('H:i:s') == $time;
}

function validateDate($id, $date, $checkIn, $checkOut)
{
$d = DateTime::createFromFormat('Y-m-d', $date);
$valid = ($d && $d->format('Y-m-d') == $date);
if ($valid == false) {
$data = "Not Valid, Wrong Date Format";
return $data;
} else {
$validCheckIn = $this->validateTime($checkIn);
$validCheckOut = $this->validateTime($checkOut);

if ($validCheckIn == false) {
$data = "Not Valid, Wrong Check In Time Format";
return $data;
}
if ($validCheckOut == false) {
$data = "Not Valid, Wrong Check Out Time Format";
return $data;
}
return $this->setTimezone($id, $date, $checkIn, $checkOut);
}
}





side note: get rid of bad habbit of mixing languages in the code. You got English named variables but also ($nip, $tanggal, $masuk, $keluar). Stick to one language (best, English)
– Marcin Orlowski
24 mins ago




($nip, $tanggal, $masuk, $keluar)





actually all the variables is in my native language, take some time for changing all the variables to english but i will try to change it only for this post on stackoverflow.
– Rayhan Adri
19 mins ago





I already changed all variables name sir @MarcinOrlowski
– Rayhan Adri
14 mins ago





What is the type of $date parameter in validateDate method? It is string right? Then how you think a DateTime object will be equal of a string?
– MASh
17 secs ago


$date


validateDate


string


DateTime


string









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

8sz7fzpG7I,cOTIyz2xY522tRghVIaMYxC0N4d3q T PBEepcNPW zl9Ki1
r7WOruBumt39x0A3dLqvetI,oy0Twsj8S 61VjEDqp4EamHA mWHoMWv0fSnCY eYUl14oSsYwTNk7R,Fw4Ao4 6iif,zFmnYUx

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results