0

I've got a little doubt.

How I can know the timestamp from day X, about hour 00:00:00 till 23:59:59?

I guess that time() just gives you the current timestamp, and I would need the timestamp from the beginning of a day to the final one so I could check my DB in MySQL for a moment between those times.

Ed Heal
  • 57,599
  • 16
  • 82
  • 120
Ardilla
  • 51
  • 1
  • 2
  • 10
  • In http://stackoverflow.com/questions/113829/how-to-convert-date-to-timestamp-in-php you can see how you can obtain timestamp. – Mihai8 Mar 13 '13 at 11:49

4 Answers4

4
$today = new DateTime();
$morning = $today->format('Y-m-d 00:00:00');
$evening = $today->format('Y-m-d 23:59:59');
John Conde
  • 212,985
  • 98
  • 444
  • 485
4

strtotime converts date from string to timestamp.

$start_date = "2012-01-10";
$end_date = "2012-04-14";
$start = strtotime($start_date . " 00:00:00");
$end = strtotime($end_date . " 23:59:59");
artahian
  • 2,045
  • 13
  • 16
0

You could use mktime().

http://php.net/manual/en/function.mktime.php

// Set the default timezone to use. Available as of PHP 5.1
date_default_timezone_set('UTC');

// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));

// Prints something like: 2006-04-05T01:02:03+00:00
echo date('c', mktime(1, 2, 3, 4, 5, 2006));
karmafunk
  • 1,423
  • 10
  • 17
  • thanks for helping, @aram90 gave me the exact point what i wanted, the timestamp from a day. thanks anyways! – Ardilla Mar 13 '13 at 12:02
0

Have a look at the strtotime function, e.g.

$date1 = 'today 00:00:00';
$date2 = 'today 23:59:59';
$unixTime1 = strtotime($date1);
$unixTime2 = strtotime($date2);
Nick
  • 6,148
  • 2
  • 28
  • 45