php date formatting api
Budget: $10 – $30 USD
can you help with a date formating api.
The input is a date like 20/05/2022, dd/mm/yyyy and output would be like this
{
"valid ": true,
"string_date": "05/20/2023",
"string_date_time": "2023-05-20 00:00:00"
}
But my code is not picking up dates like 20/5/2023 and 7/5/2023
Here is the code i have
public function validatedateapi(){
$postdate = $_POST['date'];
$output_array_dates1 = $this->find_date(strtolower($postdate));
$checkdateis = "";
if(count($output_array_dates1)>1) {
$checkdateis = $output_array_dates1['day']."-".$output_array_dates1['month']."-".$output_array_dates1['year'];
}
if(validateDate($checkdateis)){
$checkdateis = $checkdateis;
}
if(!empty($checkdateis)){
echo json_encode(array("valid "=>true,"string_date"=>date("m/d/Y",strtotime($checkdateis)),"string_date_time"=>date("Y-m-d H:i:s",strtotime($checkdateis)))) ;
}else{
preg_match( '/([0-9]?[0-9])[\.\-\/ ]+([0-1]?[0-9])[\.\-\/ ]+([0-9]{2,2})/', $postdate, $matches );
if(validateDate($matches[0],"d-m-y") && isset($matches[0])){
$d = DateTime::createFromFormat("d-m-y", $matches[0]);
echo json_encode(array("valid "=>true,"string_date"=>$d->format("m/d/Y"),"string_date_time"=>$d->format("m/d/Y H:i:s"))) ;
}else if(validateDate($matches[0],"d/m/y") && isset($matches[0]) ){
$d = DateTime::createFromFormat("d/m/y", $matches[0]);
echo json_encode(array("valid "=>true,"string_date"=>$d->format("m/d/Y"),"string_date_time"=>$d->format("m/d/Y H:i:s"))) ;
}
else{
echo json_encode(array("valid "=>false)) ;
}
}
}
Whats the cheapest you can do this for please?
The input is a date like 20/05/2022, dd/mm/yyyy and output would be like this
{
"valid ": true,
"string_date": "05/20/2023",
"string_date_time": "2023-05-20 00:00:00"
}
But my code is not picking up dates like 20/5/2023 and 7/5/2023
Here is the code i have
public function validatedateapi(){
$postdate = $_POST['date'];
$output_array_dates1 = $this->find_date(strtolower($postdate));
$checkdateis = "";
if(count($output_array_dates1)>1) {
$checkdateis = $output_array_dates1['day']."-".$output_array_dates1['month']."-".$output_array_dates1['year'];
}
if(validateDate($checkdateis)){
$checkdateis = $checkdateis;
}
if(!empty($checkdateis)){
echo json_encode(array("valid "=>true,"string_date"=>date("m/d/Y",strtotime($checkdateis)),"string_date_time"=>date("Y-m-d H:i:s",strtotime($checkdateis)))) ;
}else{
preg_match( '/([0-9]?[0-9])[\.\-\/ ]+([0-1]?[0-9])[\.\-\/ ]+([0-9]{2,2})/', $postdate, $matches );
if(validateDate($matches[0],"d-m-y") && isset($matches[0])){
$d = DateTime::createFromFormat("d-m-y", $matches[0]);
echo json_encode(array("valid "=>true,"string_date"=>$d->format("m/d/Y"),"string_date_time"=>$d->format("m/d/Y H:i:s"))) ;
}else if(validateDate($matches[0],"d/m/y") && isset($matches[0]) ){
$d = DateTime::createFromFormat("d/m/y", $matches[0]);
echo json_encode(array("valid "=>true,"string_date"=>$d->format("m/d/Y"),"string_date_time"=>$d->format("m/d/Y H:i:s"))) ;
}
else{
echo json_encode(array("valid "=>false)) ;
}
}
}
Whats the cheapest you can do this for please?