1

I have a application with MySQL query where I need add hours to the datetime. For this purpose is easy to use for example

SELECT DATE_ADD(some_column, INTERVAL 4 HOUR) FROM some_table

I'm using Laravel framework and only for testing I'm using SQLite where this date_add function does not exists and I have to use this query

SELECT datetime(some_column, "+4 Hour") FROM some_table

and this is the problem because application is using mysql while PHPUnit is using sqlite. Is there any workaround how to use function to add hours to the datetime which will works for both databases or is there any effective way how to do it?

Jaroslav Klimčík
  • 4,548
  • 12
  • 39
  • 58

3 Answers3

0

Laravel has built in datetime in schembuilder $table->timestamps();

More help https://laravel.com/docs/4.2/schema#adding-columns

Marcus
  • 1,850
  • 1
  • 12
  • 24
0

You can change your date with PHP :

  • date('Y-m-d H:i:s', strtotime('+4 hours', strtotime($date)))

or

  • date('Y-m-d H:i:s', strtotime('+4 hours', $date)) if your date is a timestamp
EkinOf
  • 451
  • 1
  • 7
  • 18
0
$date = Carbon:now()->addHours(4);

That will generate a timestamp that is 4 hours ahead of current time

Ghost Worker
  • 640
  • 6
  • 17