Question

Would the date function for php recognize this code, and convert it to a Date Stamp

$date= date('$_POST["Month1"]/$_POST["Date1"]/$_POST["Year1"]');

?

Was it helpful?

Solution

Your syntax is unclear and not works because of single quotes. Better try with:

$date = date($_POST["Month1"] . '/' . $_POST["Date1"] . '/' . $_POST["Year1"]);

If your post data contains format, like m, d, Y - it's ok. But if you pass date like 4, 21, 2014 - date() will not work. Convert it to timestamp with:

$timestamp = strtotime($_POST["Month1"] . '/' . $_POST["Date1"] . '/' . $_POST["Year1"]);

OTHER TIPS

Your syntax is wrong, as already stated, but it's also better for avoiding formatting issues to actually just pass in the variables individually to mktime(), like this:

$timestamp = mktime(0, 0, 0, $_POST["Month1"], $_POST["Date1"], $_POST["Year1"]);

That way you aren't having to pass the variables you already have broken up through any extra steps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top