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
Array to Object and Object to Array in PHP - Interesting Behaviour
Adding a Namespace When Using Simplexmlelement
Decrypting Strings in Python That Were Encrypted with Mcrypt_Rijndael_256 in PHP
How to Perform an Action Every 5 Results
How to Execute PHP with Extension File.Php.Jpg
PHP Get Dropdown Value and Text
Jquery Mobile: Sending Data from One Page to the Another
PHP Unable to Load PHP_Curl.Dll Extension
Invoke External Shell Script from PHP and Get Its Process Id
How to View/Open a Word Document in My Browser Using with PHP or HTML
How to Display Special Characters in PHP
How to Get Exact Browser Name and Version
Installing Mcrypt Extension for PHP on Osx Mountain Lion
Get Image Height and Width as Integer Values
Use of Initialization Vector in Openssl_Encrypt