Adding time in PHP

前端 未结 8 1108
别那么骄傲
别那么骄傲 2020-12-22 10:37

I am pulling a datetime from a mysql db and i would like to add X hours to it then compare it to the current time. So far i got

$dateNow = strtotime(date(\'Y         


        
8条回答
  •  我在风中等你
    2020-12-22 10:51

    Here's how I'd do it:

    1. Pull the time from the database using the UNIX_TIMESTAMP() function.

    2. The UNIX timestamp is in seconds, so add 4*60*60 to it.

    3. Convert the modified UNIX timestamp to a date using PHP's localtime() or strftime() function.

      query("SELECT UNIX_TIMESTAMP(someDatetimeColumn) ...");
      . . .
      $dbTimeAdjusted = localtime($row[0] + 4*60*60);
      

提交回复
热议问题