Reputation: 13
Would the date function for php recognize this code, and convert it to a Date Stamp
$date= date('$_POST["Month1"]/$_POST["Date1"]/$_POST["Year1"]');
?
Upvotes: 0
Views: 63
Reputation: 37045
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.
Upvotes: 0
Reputation: 152206
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"]);
Upvotes: 1