Date format from form field

I am trying to get the full date from form field using the date function and post method.

$fromdate = $_POST[‘sdate’];
$todate = $_POST[‘edate’];
$fromday = date(‘F j, Y, g:i a’,’$fromdate’);
$today1 = date(‘F j, Y, g:i a’,’$todate’);

When trying to print i get the right format but i get extra information not sure from where? I am getting the date from the form fields of type date.

Code Output:
March 19, 2020, 4:16 pm,$31202019pm31Asia/Dubai

why i am getting the second part!

Why are you placing variables between single quotes?

It should be:

$fromdate = $_POST['sdate'];
$todate = $_POST['edate'];
$fromday = date('F j, Y, g:i a', $fromdate);
$today1 = date('F j, Y, g:i a', $todate);

Furthermore i hope that the $_POST elements CONTAIN timestamps and not date strings?

Otherwise you will have to use strtotime() to convert the datestring to a timestamp.

Sponsor our Newsletter | Privacy Policy | Terms of Service