0

I have a query:

$time = time();
$query = "SELECT timestamp FROM sales WHERE timestamp < '$time'";

=

The timestamp (in seconds, i.e. 1554901254) in that DB is 4 hours ahead of time(). Is there a way to adjust that timestamp within the query? I know something like $time = time()+14400 should work, but can I adjust timestamp itself to let's say date_default_timezone_set('America/New_York');?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Signs7771
  • 51
  • 6
  • Your question is a bit unclear! In case you are looking to make MySQL aware of your timezone, see https://stackoverflow.com/questions/12296780/mysql-set-timezone-in-php-code – Amfasis Apr 10 '19 at 13:35

2 Answers2

2

You can do something like that,

 where timestamp < date_add($time, INTERVAL 4 hour)

Documentation for date_add.

Rahul
  • 18,271
  • 7
  • 41
  • 60
0
date_default_timezone_set('America/New_York');

$datetime = new DateTime();
$datetime->setTimestamp($yourTimestamp);
echo $datetime->getTimezone()->getName();
echo $datetime->format(DATE_ATOM);

This should do the trick for you.

Lulceltech
  • 1,662
  • 11
  • 22