문제

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

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

?

도움이 되었습니까?

해결책

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"]);

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top