Adding 30 Minutes to Datetime PHP/Mysql

how to add minutes to datetime field then select all that matches in mysql?

The syntax in MySQL uses interval, not dateadd() (at least with your syntax). Your question doesn't make that much sense, unless I interpret "actual active date" as the current date time:

SELECT *
FROM records
WHERE reposted = 1 AND now() > active_date + interval 10 minute;

How to add for example 30 or 60 minutes into a specific time

I think you need to parse the value in php. Try something like this:

$timestamp = strtotime('12:00') + 30*60;
$time = date('H:i', $timestamp);

Adding minutes to date time in PHP

$minutes_to_add = 5;

$time = new DateTime('2011-11-17 05:05');
$time->add(new DateInterval('PT' . $minutes_to_add . 'M'));

$stamp = $time->format('Y-m-d H:i');

The ISO 8601 standard for duration is a string in the form of P{y}Y{m1}M{d}DT{h}H{m2}M{s}S where the {*} parts are replaced by a number value indicating how long the duration is.

For example, P1Y2DT5S means 1 year, 2 days, and 5 seconds.

In the example above, we are providing PT5M (or 5 minutes) to the DateInterval constructor.

adding time and date to datetime in mysql using php?

Check this:

$end_date = date("Y-m-d H:i:s", strtotime(date("Y-m-d H:i:s"). ' + 5 days'));

MySql store the datetime in YYYY-MM-DD HH:MM:SS format.

Mysql datetime format add 10 minutes

I like the INTERVAL expr unit notation. It feels more readable to me:

SELECT NOW(),
NOW() + INTERVAL 10 MINUTE;

+--------------------------------+-------------------------------+
| NOW() | NOW() + INTERVAL 10 MINUTE |
+--------------------------------+-------------------------------+
| August, 12 2013 14:12:56+0000 | August, 12 2013 14:22:56+0000 |
+--------------------------------+-------------------------------+

If you want to select existing rows and add 10 minutes to the result:

SELECT the_date + INTERVAL 10 MINUTE FROM tbl;

If you want to alter existing rows stored in a table, you could use:

UPDATE tbl SET the_date = the_date + INTERVAL 10 MINUTE;

If you want increase by force a value by 10 minutes while inserting, you need a trigger:

CREATE TRIGGER ins_future_date BEFORE INSERT ON tbl
FOR EACH ROW
SET NEW.the_date = NEW.the_date + INTERVAL 10 MINUTE


Related Topics



Leave a reply



Submit