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
  • 59,252
  • 17
  • 87
  • 127
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
  • 217,595
  • 99
  • 455
  • 496
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,093
  • 14
  • 17
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,453
  • 12
  • 20
  • 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,316
  • 2
  • 29
  • 47