0

I have a MySQL database table in which I want to store scheduled datetime records. I'm trying to use PHP date function $schedule = date('Y-m-d H:i:s');

I want to add 1 minute to each record but keep the adding like ++:

// needed result:
2018-02-08 10:00:00
2018-02-08 10:01:00
2018-02-08 10:02:00

My code looks slimier to this (tried to use stortime but it didn't worked):

$schedule = date('Y-m-d H:i:s');
//$schedule = strtotime('2018-02-18 19:00 + 1 minute'); 

foreach ($rows as $row) {
    $sql = "UPDATE table SET schedule='$schedule'";
    $stm = $db->query($sql);
}

Looking for a solution to keep date and time format as described with simple increase by minutes...

Genius
  • 13
  • 3

2 Answers2

0

Try

$current_time = time();
$next_time = strtotime('+1 minute', $current_time);
$schedule = date('Y-m-d H:i:s', $next_time);
Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
7-zete-7
  • 712
  • 4
  • 12
0

Try below code. First get the date/time of $schedule then add 1 to the $schedule date/time after update query, so after adding 1 minute to database it will again add 1 minute and so on.

$schedule = date('Y-m-d H:i:s');

foreach ($rows as $row) {
    $sql = "UPDATE table SET schedule='$schedule'";
    $stm = $db->query($sql);
    $schedule = date("Y-m-d H:i:s", strtotime('+1 minutes', $schedule));

}
Pankaj Makwana
  • 3,030
  • 6
  • 31
  • 47
  • `strtotime('+1 minutes', $schedule)` will fail : _"A non well formed numeric value encountered"_ – Syscall Feb 08 '18 at 10:26