Lewis Day Lewis Day - 2 months ago 8
PHP Question

convert a date into a timestamp

Okay so basically I have two variables one called

$day
and another called
$time
what I'm trying to do is convert both of these into a unix time-stamp so for example;

$day = 'Monday';
$time = '14:00:00';


So what I'm looking for is a
$timestamp
variable that would echo out the next
Monday
coming up at
14:00:00
in a unix timestamp format.

I'm guessing the hardest part of this would be the fact that the day is not a specific date more a day of the week meaning it would have to select the next
monday
coming up, or the next
tuesday...
for example.

Thanks for any help.

Answer

The constructor for the DateTime class is pretty good at figuring this sort of thing out:

<?php
$day = 'Monday';
$time = '14:00:00';

$date = new DateTime("next $day $time");
echo $date->getTimestamp();
// 1475503200