0

I'm having trouble converting midnight date into timestamp. I'm getting via AJAX POST method timestamp (including time zone offset) from klient, so then I'm converting this to a midnight date like this:

$timestamp = 1463990400; // for example
echo date('d-m-Y H:i:s', strtotime('today', $timestamp));

This line output is: 23-05-2016 00:00:00

And I would love to convert this midnight date time into timestamp to create SQL SELECT.

Is there any solution?

Thamilhan
  • 13,040
  • 5
  • 37
  • 59
Petr Bečka
  • 774
  • 3
  • 16
  • 39
  • I've tried to use format() method and expolde() function to create an array, but neither of this ways worked for me so far. Maybe I'm doing something wrong.. – Petr Bečka May 30 '16 at 07:23
  • Good thing too know. Could you enrich your Original Post with what you did? – J. Chomel May 30 '16 at 07:27
  • Of course, sorry for that. – Petr Bečka May 30 '16 at 07:35
  • I don't understand the target... is it to use PHP to convert "23-05-2016 00:00:00" back to 1463990400 ? – Barry May 30 '16 at 07:51
  • It's not like convert back, because $timestamp could include time offset or sime time, it's just regular date time, so it can be like "23-05-2016 07:15:20", so first I need to get a midnight of this date time and then create timestamp.. – Petr Bečka May 30 '16 at 07:56

1 Answers1

0

Finally found way how to solve my problem with mktime() function:

$offset = date('d-m-Y H:i:s', strtotime('today', $datum_to));
$parts = preg_split('/\s+/', $offset);
$date_convert = explode("-", $parts[0]);
$time_convert = explode(":", $parts[1]);

$this_tz_str = date_default_timezone_get();
$this_tz = new DateTimeZone($this_tz_str);
$now = new DateTime("now", $this_tz);
$offset = $this_tz->getOffset($now);

$second_starttimeUTC = mktime(0, 0, 0, $date_convert[1], $date_convert[0], $date_convert[2])+$offset;
Petr Bečka
  • 774
  • 3
  • 16
  • 39