php - Adding date and time variables and getting unix timestamp


I foolishly thought you could just add the two and somehow magically get away with doing it the following way:

$time = mysql_real_escape_string(stripslashes($_POST['time']));
$date = mysql_real_escape_string(stripslashes($_POST['date']))." ".$time;
$date = strtotime($date);

Obviously there is no way this would work. Basically, I have two fields, one where the user enters in the date and another for time. I need my timestamp to reflect both inputs. Any ideas on how this can be done?

EDIT: For example: I input 09/04/2013 for the date and 7:25 for the time and got: 1378297500 which equals to Wed, 04 Sep 2013 12:25:00 GMT




If you run this code:

$dt = strtotime('09/04/2013 7:25');
echo $dt . " - " . gmdate('r', $dt);

You will get:

1378279500 - Wed, 04 Sep 2013 12:25:00 +0000

If you're getting your date & time inGMT then set timezone accordingly before callingstrtotime like this:


People are also looking for solutions to the problem: How to retrieve an images from PHp myadim database and display in android list view?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.